How do I diff two files in MSBuild? I cannot find any specific task to do it.
If possible, is it also possible to exclude certain rows, or patterns in the files eg.
2009-12-09T10:03:07.6888125+02:00
You're gonna have to write your own MSBuild task which wraps some difftool commandline app. For commandline apps, you can inherit from the ToolTask class, which provides quite a bit of command line plumbing.
<Target Name="CheckFileSyncStatus" BeforeTargets="Build" Inputs="#(FilesToSync -> '..\..\..\folder1\folder2\%(Filename)%(Extension)')" Outputs="#(FilesToSync)">
<Exec Command="FC "%(FilesToSync.Filename)%(FilesToSync.Extension)" "..\..\..\folder1\folder2\%(FilesToSync.Filename)%(FilesToSync.Extension)"">
<Output TaskParameter="ExitCode" PropertyName="FCExitCode" />
</Exec>
<Error Text="[HP.OneDriver.Win10S.DriverProperties]:Files out of sync from source: %(FilesToSync.Filename)%(FilesToSync.Extension)" Condition="FCExitCode == 1" />
Related
I'm struggling to figure out this task in Ant. There are not many examples in the documentation and I can;t seem to find a solid answer online.
I need to scan a directory that contains several sub-directories eg
Root
TargetFolder
Folder A
Folder B
Folder C
...
Folder Z
I need to run the build.xml from Root, and with a task scan all sub-directories of TargetFolder (so Folder A, B, C etc) and if the directory contains a file, foo.txt, run an <apply> task for that directory.
I'm able to do a <dirset> and get the list of sub-directories. And I can do a separate <fileset> to scan TargetFolder and get all occurences of foo.txt. But, I have no clue how to combine these things, or how to go about doing a simple file check attached to the <apply> task.
Here is one way. Use a dirset as you say, with the <present> selector:
<dirset id="dirs" dir="Root">
<present targetdir="Root">
<mapper type="glob" from="*" to="*/foo.txt" />
</present>
</dirset>
<apply executable="ls">
<arg value="-alF" />
<dirset refid="dirs" />
</apply>
You could merge both into one task:
<apply executable="ls">
<arg value="-alF" />
<dirset id="dirs" dir="Root">
<present targetdir="Root">
<mapper type="glob" from="*" to="*/foo.txt" />
</present>
</dirset>
</apply>
How can i add some custom file created by MSBuild to project output?
i.e. I have blank .csproj, I add Exec task to Target that generates some file.txt and now i want to include this file into "primary output" or "content files".
Thanks,
Marek
Generally, you just need to include the output files you have and then copy them to the output directory.
<CreateItem Include="$(SourcePath)\file.txt">
<Output ItemName="FilesToCopy" TaskParameter="Include" />
</CreateItem>
<Copy SourceFiles="#(FilesToCopy)" DestinationFolder="$(OutDir)" />
There's also a variable $(OutputDirectory) for the immediate project. There are many other properties you may find useful also:
https://msdn.microsoft.com/en-us/library/ms164309.aspx
https://msdn.microsoft.com/en-us/library/ms164313.aspx
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 currently have this command:
copy /b *.txt newfile.txt
But I want to include all files with folders as well.
How can I do this? Is it possible to add this to Apache Ant as well?
I also consider doing this to minify JS files.
Im using windows and would like a command to run or batch file but having issues.
Is there anyway to remove lines as well?
Is there a better command to use than the one I am currently using?
UPDATE:
<target name="concatenate" description="Concatenate all js files">
<concat destfile="build/application.js">
<fileset dir="js" includes="*.js" />
</concat>
</target>
<target name="compress" depends="concatenate" description="Compress application.js to application-min.js">
<apply executable="java" parallel="false">
<filelist dir="build" files="application.js" />
<arg line="-jar" />
<arg path="C:\yuicompressor-2.4.7\build\yuicompressor-2.4.7.jar" />
<srcfile />
<arg line="-o" />
<mapper type="glob" from="*.js" to="build/*-min.js" />
<targetfile />
</apply>
Now i am using the above code but cant get it to include files within folders
As oers pointed out in the comment, Ant patterns use ** to recursively match directories. Here is the relevant Patterns section from the Ant manual:
To make things a bit more flexible, we add one extra feature, which makes it possible to match multiple directory levels. This can be used to match a complete directory tree, or a file anywhere in the directory tree. To do this, ** must be used as the name of a directory. When ** is used as the name of a directory in the pattern, it matches zero or more directories. For example: /test/** matches all files/directories under /test/, such as /test/x.java, or /test/foo/bar/xyz.html, but not /xyz.xml.
There is one "shorthand": if a pattern ends with / or \, then ** is appended. For example, mypackage/test/ is interpreted as if it were mypackage/test/**.
The "concatenate" target above would be:
<target name="concatenate" description="Concatenate all js files">
<concat destfile="build/application.js">
<fileset dir="js" includes="**/*.js" excludes="**/*.min.js" />
</concat>
</target>
In my NAnt project, I'd like to fire off a batch file and just forget about it. So I tried pulling something like this:
<exec program="start" commandline="cmd /c c:\mybat.bat" />
But NAnt complains:
'start' failed to start
The system cannot find the specified fileBlockquote
start cmd /c c:\mybat.bat works if I run it straight from the command line. Ideas?
Take a look at this AsyncExec task. Also, IIRC start is not a real program but a command, which is why you're getting that error.
A simpler alternative to use it the:
<exec ... pidproperty="pid1" spawn="true" />
<exec ... pidproperty="pid2" spawn="true" />
<exec ... pidproperty="pid3" spawn="true" />
<waitforexit pid="${pid1}" />
<waitforexit pid="${pid2}" />
<waitforexit pid="${pid3}" />
See NAnt exec task and NAntContrib waitforexit task