Copy only modified and new files from source to destination in nant script - nant

Currently we are using copy command to copy files from one location to other, but it is coping all files over and again. Here I want to copy only modified and new files from source to destination.
Can any one please help me in this?
Here is sample code:
<copy overwrite="true" todir="destination">
<fileset basedir="source">
<include name="**/*"/>
</fileset>
</copy>

This would copy only modified files from source folder to destination folder:
<exec program="C:\Windows\System32\xcopy.exe" failonerror="false" >
<arg line="${source} ${destination} /D /E /C /Q /H /R /Y /K" />
</exec>

Related

Copy files to bin folder with .nuspec files

I have .nuspec file to create my package which contains nothing but a folder with text and other format files. I pack the folder like this:
<files>
<file src="myData\**\*.*" target="content" copyToOutput="true" />
</files>
When I install the nuget package I want this folder to be in my bin folder/output folder so that my program can relatively reference the files present. How can I achieve this since my nuget package doesn't have any .csproj to have .target file to copy files?
This isn't the exact answer to your question, but I am not sure if you can achieve this without a .target file. As a workaround, you can create an empty .csproj with a .target file which shall copy the items of your content folder:
<Project>
<Target Name="CopyToDeployFolder" AfterTargets="Build">
<Exec Command="xcopy.exe $(MSBuildThisFileDirectory)\..\content $(OutputPath) /e /y /i /r" />
</Target>
<Target Name="CopyToPublishFolder" AfterTargets="Publish">
<Exec Command="xcopy.exe $(MSBuildThisFileDirectory)\..\content $(PublishDir) /e /y /i /r" />
</Target>
</Project>

Moving from NAnt to PowerShell. Copy/Delete replacement

Please help me to translate this to PowerShell:
<delete>
<fileset defaultexcludes="false" basedir="${svnRepository}">
<include name="**/*" />
<exclude name="**/.svn" />
<exclude name="**/.svn/**" />
</fileset>
</delete>
<!-- Copy entire output of successful build into the svn working folder -->
<copy todir="${svnRepository}">
<fileset defaultexcludes="false" basedir="${binariesFolder}">
<include name="**/*" />
<exclude name="**/Bin/*.pdb"/>
<exclude name="**/Bin/*.xml"/>
</fileset>
</copy>
PowerShell
Get-ChildItem -recurse "$svnRepository" | ? {$_.FullName -notmatch '.svn'} | Remove-Item -Recurse
I've tried to write something like above, but it doesn't exclude all SVN directories in nested foldes, e.g if I have a directory C:\blabla\test with nested .svn it will ignore C:\blabla\test\.svn\* but at the same time it will try to remove C:\blabla\test itself
Are you sure you have to do anything here? Get-ChildItem already doesn't include hidden folders like .svn, .git etc. and only includes them when you specify the -Force parameter.

How to copy modified files to several servers using ANT

This script works good for the first server (server1), but it doesn't work for the second pass (server2) as at that point all 'modified' files are already flagged by the first pass.
<macrodef name="copythings">
<attribute name="todir"/>
<sequential>
<scp todir="#{todir}" trust="true">
<fileset dir=".">
<modified/>
<include name="cgi-bin/Application/" />
<exclude name="**/*.log" />
</fileset>
</scp>
</sequential>
</macrodef>
<target name="deploy">
<copythings todir="server1"/>
<copythings todir="server2"/>
</target>
I'd suggest copying the files from the fileset to a temporary folder first.
And copy to the server from that directory.
copy required files to a tempory folder
run the targets and use the temporay folder as base/filset for scp
delete the temporary folder

How to rebuild solution using NAnt?

I am using following command in NAnt build file
<msbuild project="${appsdest}\${targetname}\${targetname}.sln"/>
appsdest and targetname are variable contain application project path and targetname is the variable contain project name to be rebuild.
but when using this command it build the solution but the time stamp of dlls are not updated.
I need to rebuild the solution and the latest dlls need to be place in debug folder.
can anyone tell me how to rebuild the solution using the msbuild command as written above?
Thanks
I don't use the MSBUILD tasks in NAnt, I just call the msbuild executable directly and it has worked well for me.
<target name="build">
<exec program="${MSBuildPath}">
<arg line='"${SolutionFile}"' />
<arg line="/property:Configuration=${SolutionConfiguration}" />
<arg value="/target:Rebuild" />
<arg value="/verbosity:normal" />
<arg value="/nologo" />
<arg line='/logger:"C:\Program Files\CruiseControl.NET\server\ThoughtWorks.CruiseControl.MsBuild.dll"'/>
</exec>
</target>
I write more about it here: http://enterpriseyness.com/2009/12/continuous-integration-with-cruise-control-net-nant
You need to use the 'Rebuild' target:
<msbuild project="${appsdest}\${targetname}\${targetname}.sln" target="Rebuild"/>

In nant, how to delete contents of a directory, but not the directory itself?

Suppose I were scripting a deployment using nant on a Windows server to a file share: \\server\share. I want a nant script to delete all files from the share then copy in new files.
I have this code to delete the files, but I'm getting an error that it can't delete "\server\share". But I didn't want to delete the share, just the contents in it.
<delete>
<fileset basedir="\\server\share">
<include name="**/**" />
</fileset>
</delete>
Output:
BUILD FAILED
D:\code\xxx\xxx.deploy(177,8):
Cannot delete directory '\\server\share'.
Access to the path '\\server\share' is denied.
If I modified it to instead delete contents of a directory in the share, say \\server\share\somedir, it'll delete "somedir" without error. But still, I didn't want to delete the dir, just the contents. Is there a way?
This works for me - no workarounds required:
<delete>
<fileset basedir="\\server\share">
<include name="**\*" />
</fileset>
</delete>
You could introduce an "exclude" tag and exclude a dummy file. That'll leave the root folder intact.
I'm using the following:
<target name="clean">
<delete>
<fileset basedir="${DeployTo}">
<include name="**/*" />
<exclude name="**/aspnet_client/**" />
</fileset>
</delete>
</target>
Taking cue from nsr81, I was able to come up with this workaround that works for me:
<touch file="${DeployTo}/deleteme" />
<delete>
<fileset basedir="${DeployTo}">
<include name="**/**" />
<exclude name="deleteme" />
</fileset>
</delete>
<delete file="${DeployTo}/deleteme" />