06 October 2005

Passing double/single quote in Nant task

Tasks like in Nant doesn't like nested quotes. If you want to pass a commandline argurement that contains double quotes (for space in directory names need double quotes around it), you will have small problem.
For example, you cann't do this:


<exec workingdir="c:workingdir\bin" basedir="c:\executableDir" program="sar.exe" commandline="/s:ContentDB.config /d:..\..\ContentDB.config /f:"my file contains space" /i" />

Have tried a few ways to escape the double quote, not very sucessful. Suddenly I find we can do this:
1) add a property at top for double/single quote
2) use it!

<property name="quote" value='"' />
...
<exec workingdir="c:workingdir\bin" basedir="c:\executableDir" program="sar.exe" commandline="/s:ContentDB.config /d:..\..\ContentDB.config /f:${quote}my file contains space${quote} /i" />

1 comment:

Anonymous said...

Surely it's not NAnt that's complaining here; it's the XML parser used by NAnt.

Couldn't the same thing be achieved with an XML entity?

<exec
workingdir="c:workingdir\bin"
basedir="c:\executableDir"
program="sar.exe"
commandline="/s:ContentDB.config /d:..\..\ContentDB.config /f:&quot;my file contains space&quot; /i"
/>