How to diff two files in NAnt - nant

How can I diff 2 text files using NAnt to produce a file containing the differences?

I suggest you to use <exec> task and call cmd with fc command that compares files. It will look something like that
<exec program="cmd.exe" commandline="/C fc file1 file2" />
You can see fc manpage here

Related

Conditional <exec> based on results of <copy>

In our nant build script for our web-based application, we <copy> a set of files to a target directory and then run aspnet_compiler over them via <exec>.
<copy> only copies files that have changed, however here is no way to pass this information to <exec>, and I want to avoid running aspnet_compiler when nothing has actually changed.
Options I've tried to find are: <copy> setting a property when any file is copied that can then be checked with <if>; or being able to create a file before the copy and doing something like <if test="any-file-newer-than(targetdir, timestampfile)">. Even better would be if <copy> could return a list of copied files that I can then iterate over to avoid having to process the entire tree, but I think that might be asking a bit too much.
So far, I've drawn a blank: is what I'm looking for possible without writing a custom extension?
Why don't you just simply replace copy task with robocopy? (you're on Windows, right?)
Robocopy returns different exit codes on different successful copy situations:
https://ss64.com/nt/robocopy-exit.html
For example:
0 - ok, nothing copied
1 - ok, something copied
You could do something like this:
<exec program="robocopy.exe" commandline="${SourceDir} ${DestDir}" failonerror="false" resultproperty="ExitCode" />
<fail unless="${ExitCode < 8}" message="Failed to copy"/> <!-- Anything between 0..7 is OK for robocopy -->
<exec unless="${ExitCode == 0}" ...

Merge txt file: TXTcollector

I am looking for an easy way (without windows commands) to merge several txt files.
Does anyone has an advice about the software TXTCollector? Is it a good one?
Thanks
A command prompt or .BAT/.CMD file can accomplish this easily by redirecting the output to a file.
type first.txt > merge.txt
type second.txt >> merge.txt
type third.txt >> merge.txt
A single redirection operator (e.g. >) will always create a new file with the output, overwriting any existing target file. Double redirection operators (e.g. >>) will append the output to an existing file or create a new file if one does not exist.
In the above .CMD script, the contents of first.txt, second.txt and third.txt will be in the new merge.txt.
EDIT Sample .CMD files
In its simplest form, a .CMD script that loops through the .txt files in a folder would look something like this.
#echo OFF
FOR %%c in (*.txt) DO TYPE %%c >> merge.txt
There is plenty of examples available on the web if you need to make adjustments for your particular situation.

Simple way to enumerate the files in a fileset in phing

I am new to phing and trying to verify if my build.xml works as expected. I am looking for a convenient way to enumerate the files in a phing fileset.
The only thing that I've been able to get working is foreach (like in how to iterate (loop) through directories in phing?). However, it feels way too complex: I have to create a subtask, and phing gets called once for every file, making the outupt list hard to parse visually.
Any better alternatives? Thanks!
With Phing 2.4.8, the <echo> task supports filesets:
http://www.phing.info/trac/ticket/792
There is currently no better way. You could grep the output, though :)
<task name="dummy">
<foreach param="filename" absparam="absfilename" target="echoFilesetFile">
<fileset refid="co"/>
</foreach>
</task>
<target name="echoFilesetFile">
<echo>file: rel:${filename}|abs:${absfilename}</echo>
</target>
then $ phing dummy | grep 'file:'

Nant, SqlCmd -v switch and spaces in nant property fails build with invalid argument

I have a nant script that ...
1. takes the content of disc-file
2. assigns that content to a nant property
3. and then calls sqlcmd with a -v passing in that property containg the content of the disc file
4. inside the sql script the contents of the file should be used by a stored proc.
The problem is that when the content of the file contains a space the nant build stops with a "Invalid argument" issue
Anone know a way around this ?
The top part of the nant script is ...
<?xml version="1.0"?>
<!-- the main name of this project -->
<project name="Hops" default="all">
<!-- BuildHistory -->
<property name="buildHistoryContents" value="" />
<xmlpeek xpath="/" file="BuildNotes.xml" property="buildHistoryContents"></xmlpeek>
<!-- <echo message="${buildHistoryContents}" /> -->
<!-- ***************** -->
<target name="ExecSql">
<echo message="running sql script : ${SqlBuildScriptsDir}${sqlBuildFileName}" />
<exec program="${SqlCmd}" commandline="-S ${SqlServerInstanceName} -E -d HBus -i ${SqlBuildScriptsDir}${sqlBuildFileName} -v vSchemaVersion=${buildHistoryContents} " />
</target>
The sql script contains the line ...
exec lsp_SchemaVersionUpsert '1.4', N'$(vSchemaVersion)'
A disc file content that works is ...
<BuildNotes>
<Note>
<buildVer>HasNotSpace</buildVer>
</Note>
</BuildNotes>
A disc file content that does not works is ...
<BuildNotes>
<Note>
<buildVer>Has Space</buildVer>
</Note>
</BuildNotes>
The use of all this is pass xml build comments to a table logging version build history for the db schema.
Does anyone know an alternate method or know a way through this ?
The next part, added after Phillip Keeley correcty solved first part (the SPACE Problem)
I simplified the original task to simplify the question.
There is also a Quoted Attribute Problem ; xml quoted attributes cause the nant build to fail with "Invalid Argument".
eg this will cause nant to choke but removing the dt attribute will enable the nant build to succeed ...
<BuildNotes>
<Note>
<buildVer>1.4</buildVer>
<dateStarted>09/24/2009 11:25:42</dateStarted>
<Item dt="20091008" >SpacesAndNoQuotedAttribute</Item>
</Note>
</BuildNotes>
Any ideas ... ?
Your problem is (of course) in line
<exec program="${SqlCmd}" commandline="-S ${SqlServerInstanceName} -E -d HBus -i ${SqlBuildScriptsDir}${sqlBuildFileName} -v vSchemaVersion=${buildHistoryContents} " />
specifically, in
-v vSchemaVersion=${buildHistoryContents}
The NAnt expression replaces property ${buildHistoryContents} with the stored value--which will include any embedded spaces. Problem is, when calling SQLCMD (I"m assuming that's what ${SqlCmd} resolves to) from a command window, the values for any and all -v parameters are space delimited -- that is, the parser hits -v, reads the next characters through the "=" as the variable name, then reads all characters after the = and through the next space (or end of line) as the value to assign to the variable, and that embedded space will mess you up bigtime.
On the command line, the work-around is to wrap the variable value in quotes:
- v MyVariable=Hello World
becomes
- v MyVariable="Hello World"
That doesn't work here, because it's XML and you have to wrap the commandline attribute of the exec element with quotes... and embedded quotes will, once again, mess you up bigtime.
I believe the work-around here is to use XML macro substitution (I quite possibly have the formal titles of these concepts wrong) for those embedded quotes. This value should be
"
Which means that the following should work:
<exec program="${SqlCmd}" commandline="-S ${SqlServerInstanceName} -E -d HBus -i ${SqlBuildScriptsDir}${sqlBuildFileName} -v vSchemaVersion="${buildHistoryContents}" " />
Please try this and see -- I may have to do something like this myself some day soon.

Nant - copy only modifiled files

I'm looking for Nant script syntax that will copy from one folder to an other all files that were modified within last 5 days.
How I can cause to to include only modified files?
Thanks
You could use robocopy. Robocopy has an option to exclude older files. See this link.
http://en.wikipedia.org/wiki/Robocopy
You would then run Robocopy for a nAnt exec task.
Hope this helps
Shiraz
The idea is quite simple:
When you need to copy files from folder 1 to folder 2 which are modified relative to each other:
<exec program="C:\Windows\System32\xcopy.exe" failonerror="false" >
<arg line="${source} ${destination} /D /E /C /Q /H /R /Y /K" />
</exec>
However, if you need to check timestamp too, you would have to create some kind of filter. This you could do either in a batch file or writing your own console app.