I want to use ANT script to delete a file.
For some reason the following script gives me the following message:
BUILD SUCCESSFUL
Total time: 0 seconds
The script I am running is:
<?xml version="1.0"?>
<project name="UpdateFlag">
<target name="deleteFlag">
<delete file="/state/update.flag" failonerror="true"/>
</target>
</project>
Please assist.
<delete file="/state/update.flag" failonerror="true"/>
Will delete the file that's is in the state directory that's on the root of your directory structure. In Unix, it would be /state/update.flag, and in Windows (on the C: drive), it would be C:\state\update.flag. Is this where the file is located?
When in doubt, run Ant with the -d and -v switches. This will print out lots of useful information (and tons of useless garbage). For example, did your delete task find a file to delete? If the file isn't there, the <delete> task won't fail.
I have a funny feeling that you actually meant to do:
<delete file="${basedir}/state/update.flag"
failonerror="true"/>
Related
In Fact, I use Visual Studio 2013, and I want to copy the _PublishedWebsites Files using a batch file after deployment of my build , so this is an image to my Build Definitions:
I'm using in the batch file, this command:
xcopy /s ...\_PublishedWebsites\subfolders ...\main\Service >> ...\output.txt
To be sure that the copy works well, I wrote the result of copying operation in output.txt, so the result is:
0 File(s) copied
I noticed that the copy operation was done before than the _Publishedfiles files are created.
Do you know how can I copy the _Publishedfiles files after their complilation ?
In addition, I don't have the rights for changing in .xaml files :(
Use publish profile and type file system which will copy _PublishedWebsites to sharelocation/location
for publish profile see
https://msdn.microsoft.com/en-us/library/dd465337%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396
If you know _PublishedWebSites directory on build machine you can copy files to path you want . You can do something like this, i used this task for same issue.
<ItemGroup >
<MyProjectSource Include="$(OutputRoot)/MySource/**/*.*" />
</ItemGroup>
<Target Name="AfterCopy" AfterTargets="WebPublish">
<Copy SourceFiles="#(MyProjectSource)"
OverwriteReadOnlyFiles="true" DestinationFolder="$(PublishFolder)/% (RecursiveDir)"/>
OutputRoot = your _PublishedWebsites path
MySource = your project
PublishFolder = your destination folder
You can do like this in your csproj file or if you use tfs build definition you can add a copy file task step to defintion and just fill paramaters.
Hi I have created simple build.bat file which is as below :
#echo off
ant -buildfile build-rj-projects.xml
pause
and my build-rj-projects.xml build file is as below :
<?xml version="1.0"?>
<project name="RJ Build Projects" default="info">
<target name="info">
<echo>Hello World - Welcome to Apache Ant!</echo>
</target>
</project>
Now when I double click on build.bat file it executes target of build-rj-projects.xml file, but suddenly console disappears ! :( .I have tried putting another target
<sleep seconds="10"/>
in build-rj-projects.xml file but it sleeps for 10 seconds for every target in build-rj-projects.xml file.Any solution ?
ant is usually a batch file. When you invoke a batch file from another batch file, the execution flow is transfered to the called one and does not return to the caller. In your case, that means the pause command is not executed because your batch file ends when ant is invoked. You need to change your calling line to
call ant -buildfile build-rj-projects.xml
using the call command, when the called batch file ends, the execution flow returns to the caller.
I'm currently working on a build process, and am running into a slight problem. I have the output directory set up for each project that I want as it's own, but now I would like to delete specific files from the main output directory (This is produced by one project that is set to be output to the build output directory)...
The directory looks like this:
Build Out Folder:
-Folder foo1
-Folder foo2
-Folder foo3
-Folder foo4
-foo.pdb
-foo.dll
Here, I need to delete both the .pdb file, and the .dll file.
I've tried putting this in my csproj file:
<Target Name ="AfterBuild">
<Delete Files="$(TeamBuildOutDir)\$(SolutionName)\**.dll"/>
<Delete Files="$(TeamBuildOutDir)\$(SolutionName)\**.pdb"/>
</Target>
Yet, haven't gotten the results wanted/predicted... I know exactly which file I need to delete (name and everything), just not how to delete them... This is not a web application, so it doesn't have to work for that criteria.
I'm having several outputs of a program that I need to compare with a "expected" ouput folder. But my problem is that the output files always have a different filename.
How can I rename all files in a folder to the same filenames in another folder. Here the example - the expected file structure (can of course change):
expected/folder1/file1.txt
expected/folder1/file2.txt
expected/folder2/file1.txt
expected/folder3/file1.txt
And my output looks like this (number of files and position is always equal):
result/folder1/fileOtherName1.txt
result/folder1/fileOtherName2.txt
result/folder2/fileOtherName1.txt
result/folder3/fileOtherName1.txt
I tried using ANT (because I know that), but was stuck, because I cannot select a file by the index (sorted alphabetically).
Here my pseudocode in ANT (but don't know how to continue):
<target name="foo">
<foreach>
<fileset dir="result" casesensitive="yes">
<include name="**/*.txt"/>
</fileset>
<antcall target="rename">
</antcall>
</foreach>
</target>
<target name="rename">
<!-- how can I access another fileset and take the correct file? -->
<!-- Here I got stuck -->
<echo message="foreach.file is ${foreach.file}" />
<echo message="foreach.dir is ${foreach.dir}" />
<echo message="foreach.name.ext is ${foreach.name.ext}" />
<echo message="foreach.name is ${foreach.name}" />
</target>
Thanks for any help, it must not be in ANT only - a BASH script or similar could do the job too.
How about
#!/bin/bash
IN_DIR="expected/folder1"
OUT_DIR="result/folder2"
IN_FILES=($IN_DIR/*)
OUT_FILES=($OUT_DIR/*)
for ((i=0; i<${#IN_FILES[#]}; i++)); do
mv ${OUT_FILES[i]} $OUT_DIR/$(basename ${IN_FILES[i]})
done
Tested it on some test dirs, and it works OK.
Note that if any of your file names contains a space, it does not work.
I personally don't know ANT, so I'll give it a shot in bash.
for i in *; do
k=1;
for j in $i/*; do
mv "$j" $i/file$k.txt;
k=$[$k+1];
done;
done
This iterates through the folders and increments a counter for every file in the folder. When we proceed to the next folder, the counter is reset.
I created a test directory structure like yours and it worked for me.
I am still learning how to use ANT well, and I wanted to understand if there is some reasonable way to do file tasks in it, similar to Rake and Make:
http://martinfowler.com/articles/rake.html#FileTasks
"With a file you are referring to actual files rather than task names. So 'build/dev/rake.html' and 'dev/rake.xml' are actual files. The html file is the output of this task and the xml file is the input. You can think of a file task as telling the build system how to make the output file - indeed this is exactly the notion in make - you list the output files you want and tell make how to make them.
An important part of the file task is that it's not run unless you need to run it. The build system looks at the files and only runs the task if the output file does not exist or it's modification date is earlier than the input file. File tasks therefore work extremely well when you're thinking of things at a file by file basis."
So in other words, let's say I want to run a custom binary and I only want that binary to run if any of the files have changed. This is related to this question, but I don't want to run the binary at all, not only pass a part of the fileset (i.e. there is only one in the fileset and I don't want the tool to run at all).
The ideal solution would also not be a loooong thing, but rather could be easily applied to any target -- perhaps using some ANT JavaScript or custom task?
Use ant-contrib outofdate task. It has exactly the properties you are asking for. Here is ant-contrib website.
Here is a template on how to integrate it into your build:
<taskdef
resource="net/sf/antcontrib/antlib.xml"
>
<classpath>
<pathelement location="${ant-contrib.jar}"/>
</taskdef>
<outofdate>
<sourcefiles path="dev/rake.xml"/>
<targetfiles path="build/dev/rake.html"/>
<sequential>
... do your work here ...
... will only run if rake.html is older than rake.xml ...
</sequential>
</outofdate>