Sunday, December 09, 2007

MSBuild Exec Task fail if we have any space in the command

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>&quot;my-external-application.exe&quot;</ToolPath>
    <Param1>&quot;my-param-value&quot;</Param1>
    <Param2>&quot;my-param-value&quot;</Param2>
 </PropertyGroup>

<Target Name="Run-External-App">
 <Exec Command="$(ToolPath) $(Param1) $(Param1)"/>
</Target>

</Project>

1 comment:

Anonymous said...

You need us if you have any of these tax problems: Back
Taxes
, Unfiled Returns, Missing Records, Threat of Levy, or, if you need an Installment Agreement or an Offers in Compromise A tax levy or garnishment or attachment are all the same thing. The terms may be used interchangeably. A wage garnishment or levy may be against any asset. In the enforcement of tax collections. We prepare all Federal and State Unfiled tax Returns The Fair Tax Act (HR
25/S 1025) is a bill in the United States Congress for changing Tax Solutions laws to replace the Internal Revenue Service (IRS) and all federal income taxes (including Alternative Minimum Tax), Past due tax returns, Past due tax returns, Past due returns, Past due taxes, Unpaid tax, Tax negotiation, Wage levy, Robert M. Adams, Bob Adams