To execute an external application using MSBuild, I use the built in Exec task. A problem we all face is spaces in command line we execute. and this makes MSBuild unhappy , the task will fail.
To correct that, we should surround the command path and any paramters with quotation, a trick from old DOS days, but this also will not work as MSBuild is an XML file and " is reserved for attributes.
The trick here is to use the " in MSBuild scripts whenever you need a " , this makes your script really ugly, here I found another guy who rasie the issue to an upper level.
My prefered way to do that is to have the external application and each parameter in a separate property; just to make the command line itself more readable.
<Project>
<PropertyGroup>
<ToolPath>"my-external-application.exe"</ToolPath>
<Param1>"my-param-value"</Param1>
<Param2>"my-param-value"</Param2>
</PropertyGroup>
<Target Name="Run-External-App">
<Exec Command="$(ToolPath) $(Param1) $(Param1)"/>
</Target>
</Project>
No comments:
Post a Comment