how can I copy one file to multiple sub directories - nant

I'm trying to use nant because I thought it would be the easiest, but i'm open to any solution that works on windows xp.
I have the following folder structure
basefolder
folder1
folder2
subfolder1
code
solutionname1
projectname.interface
projectname.simulation
projectname.testcase
bin
release
folder3
...
folderN
folder1 - folderN all have the same directory structure as folder2. I want to copy a file to the release folder in each folderN.
I currently have the following nant script
<?xml version="1.0" encoding="utf-8"?>
<project xmlns="http://nant.sf.net/release/0.90/nant.xsd" name="CopyDll" default="FileCopy">
<property name="fileToCopy"
value="C:\file.dll"
overwrite="false"/>
<property name="baseDirectory" value="${directory::get-current-directory()}" overwrite="false"/>
<target name="FileCopy"
description="Copies file to multiple directories">
<foreach item="Folder"
in="${baseDirectory}"
property="foldername">
<in>
<items>
<include name="**\**\**\*.TestCase\bin\Release"/>
</items>
</in>
<do>
<copy file="${fileToCopy}"
todir="${foldername}"/>
<echo message="Copied file to ${foldername}"/>
</do>
</foreach>
</target>
</project>
This copies file.dll to each folderN directory.
What am I doing wrong?
Is there a better way to do this?

I figured it out. I had to change my foreach to look like this
<foreach item="Folder"
property="foldername">
<in>
<items>
<include name="${baseDirectory}\**\*.TestCase\bin\Release"/>
</items>
</in>
<do>
<copy file="${fileToCopy}"
todir="${foldername}"/>
<echo message="Copied file to ${foldername}"/>
</do>
</foreach>

Related

How do I delete a folders that match pattern in phing

I have a build_ folders in my directory like build_10320 or build_10321.
I need to write a target clean that deletes such a folder.
I am trying doing this
<target name="clean">
<echo msg="clean directory ./build_" />
<delete includeemptydirs="true" verbose="true" failonerror="false" >
<fileset dir="./">
<include name="./build_*" />
</fileset>
</delete>
</target>
But this doesn't work. Kindly help.
Phing still doesn't have the <dirset> feature working (which would be the natural choice). You can however make this work using <exec> & the relevant command for deleting files from your operating system.
For linux:
<exec command = "rm -rf ./build_*" passthru = "true" />
A <fileset> returns, as the name suggests, only files.
There is an undocumented <dirset> type that unfortunately cannot be used with <delete> at the moment.
With Phing 3.x you can use <dirset> inside the <delete> task.
<project name="delete-with-dirset" default="clean" basedir=".">
<target name="clean">
<echo msg="clean directory ./build_" />
<delete includeemptydirs="true" verbose="true" failonerror="false">
<dirset dir="./">
<include name="./build_*" />
</dirset>
</delete>
</target>
</project>

error CS0246: The type or namespace name 'Form1' could not be found

Currently I am developing a NAnt script to build a Windows forms application. After build the NAnt script, I am getting the error as
error CS0246: The type or namespace name 'Form1' could not be found
(are you missing a using directive or an assembly reference? )
BUILD FAILED
C:\Program
Files\NAnt\examples\SampleWindowsApplication\Sample.Build(24,10):
External Program Failed:
C:\Windows\Microsoft.NET\Framework\v3.5\csc.exe (return code was 1)”
Can anyone please advise to resolve this issue?
Please find my code below.
<?xml version="1.0"?>
<project name="SampleWindowsApplication" default="run">
<property name="basename" value="SampleWindowsApplication"/>
<property name="debug" value="true"/>
<target name="clean">
<delete>
<fileset>
<include name="bin/${basename}-??.exe"/>
</fileset>
</delete>
</target>
<target name="build">
<mkdir dir="bin" />
<assemblyfileset id="Sample.assemblies">
<include name="C:\Program Files\NAnt\examples\SampleWindowsApplication\SampleWindowsApplication\Assemblies\Sam.Grid.Base.dll" />
<include name="C:\Program Files\NAnt\examples\SampleWindowsApplication\SampleWindowsApplication\Assemblies\Sam.Grid.Windows.dll" />
<include name="C:\Program Files\NAnt\examples\SampleWindowsApplication\SampleWindowsApplication\Assemblies\Sam.Shared.Base.dll" />
<include name="C:\Program Files\NAnt\examples\SampleWindowsApplication\SampleWindowsApplication\Assemblies\Sam.Shared.Windows.dll" />
<!--<include name="C:\Program Files\NAnt\examples\SampleWindowsApplication\SampleWindowsApplication\Assemblies\System.Windows.Forms.dll" />-->
</assemblyfileset>
<csc target="exe" output="bin/${basename}.exe" debug="${debug}" >
<references refid="Sample.assemblies" />
<resources>
<include name="C:\Program Files\NAnt\examples\SampleWindowsApplication\SampleWindowsApplication\licenses.licx"/>
</resources>
<sources>
<include name="C:\Program Files\NAnt\examples\SampleWindowsApplication\SampleWindowsApplication\Program.cs"/>
</sources>
</csc>
</target>
<target name="run" depends="build">
<exec program="bin/${basename}-cs.exe" basedir="."/>
</target>
</project>
Thanks in advance.
This is typically cause when you add a new file to your solution but don't commit them.
Check to make sure that Form1.cs and Form1.Designer.cs have been added to your source control repository. It looks like your project file was added and committed correctly but some source control tools require you to manually add new files before committing them.

Prune old files in a directory with phing

This target works fine
<target name="cleanlogs">
<echo msg="clean log do nothing !!!!not ready!!!!" />
<fileset dir="/var/www/myapp/log" id="deleteLogs">
<include name="**/debug*.log" />
</fileset>
<delete>
<fileset refid="deleteLogs" />
</delete>
</target>
I want add something like
<date datetime="xxxxxx" when="before"/>
or
<date seconds="xxxxxx" when="before"/>
to delete only logs older than 5 days
How to build xxxxx in phing ??
<tstamp>
dont return "timestamp" :-/
Here is a proposition of solution
<?xml version="1.0" encoding="UTF-8"?>
<project name="Project" default="format" basedir=".">
<target name="format">
<tstamp>
<format property="DATE" pattern="%s" />
</tstamp>
<php expression="${DATE}-(3600*24*5)" returnProperty="NEWDATE"/>
<php expression="time()-(3600*24*5)" returnProperty="EVALUATEDTIME"/>
<echo>DATE = ${DATE}</echo>
<echo>NEWDATE = ${NEWDATE}</echo>
<echo>EVALUATEDTIME = ${EVALUATEDTIME}</echo>
</target>
</project>
Actually you can put anything in the eval and directly compute whatever you need.

How to echo the contents of a fileset in Nant?

Was trying to do something like this:
<copy>
<fileset id="mySet">
<include name="*.sql" />
</fileset>
</copy>
<echo message="Copied files: ${mySet} to directory: ${Folder}." />
But i get the following error:
'id' is an invalid attribute for a
tag. Datatypes can only be
declared at Project or Target level.
Thanks
You can do this by looping over the files in the set.
<fileset id="mySet">
<include name="*.sql" />
</fileset>
<copy>
<fileset refid="mySet" />
</copy>
<foreach item="File" property="filename">
<in>
<items refid="mySet" />
</in>
<do>
<echo message="Copied files: ${filename} to directory: ${Folder}." />
</do>
</foreach>
But depending on verbosity level the result of the copy action is echoed anyway.

nant exclude folder

I am looping though my folders and need to exclude the svn folders. I thought I could simply add the exclude element, though that doesnt seem to work.
<foreach item="Folder" property="foldername">
<in>
<items>
<include name="YOUR_FOLDER\**" />
<exlcude name="YOUR_FOLDER\**/_svn" />
</items>
</in>
<do>
<foreach item="File" property="filename" in="${foldername}">
<do>
<echo message="${filename}" />
</do>
</foreach>
</do>
</foreach>
Can somebody help?
It works when adding simply:
<exclude name="YOUR_FOLDER\**_svn**" />
You'll want to include the .svn directories and everything in them as well, otherwise the exclude mask will only hit the .svn directories, but not .svn/prop-base, .svn/props, .svn/text-base and so on.
<foreach item="Folder" property="foldername">
<in>
<items>
<include name="YOUR_FOLDER/**" />
<exclude name="YOUR_FOLDER/**/.svn/**" />
<exclude name="YOUR_FOLDER/**/_svn/**" />
</items>
</in>
<do>
<foreach item="File" property="filename" in="${foldername}">
<do>
<echo message="${filename}" />
</do>
</foreach>
</do>
</foreach>
Also, are you really using the alternative _svn naming scheme for Subversion's data directories?
<copy failonerror="true" overwrite="true" todir="${BusinessServicesTarget}">
<fileset basedir="${BusinessServicesPath}">
<exclude name="*.*" />
<include name="/**/*.as?x" />
<exclude name="/**/**_SVN**" />
You need to use it in copy function not in foreach.