How to escape quote marks in Exec Command in MSBuild

Msbuild

Msbuild Problem Overview


I'm trying to build an MSBuild script that maps a network drive to a drive letter in the script, but unfortunately the path to the target folder includes an embedded space. The embedded space causes the mapping to fail, and I don't know if it is possible to escape quotes around the path. I've tried double quote marks, but MSBuild doesn't like it (either that or Windows XP doesn't like it). Anyone know how to code this beast so the map works?

<Exec Command="net use x: \\ofmapoly703\c$\program files\ar\iap /user:$(UserID) $(Password)"
WorkingDirectory="c:\"
ContinueOnError="false"
/>

The embedded space of course occurs in "program files".

Msbuild Solutions


Solution 1 - Msbuild

Use &quot; to encode the double quotes that you want net to see inside the Command attribute value :

<Exec Command="net use x: &quot;\\ofmapoly703\c$\program files\ar\iap&quot; /user:$(UserID) $(Password)" 
WorkingDirectory="c:\" 
ContinueOnError="false" 
/> 

Solution 2 - Msbuild

You can use single quotes for command ,e.g.

  <Exec Command='explorer.exe "$(DestinationDir)"' IgnoreExitCode="true" />

(From https://stackoverflow.com/questions/2387456/msbuild-exec-task-without-blocking/6528765#6528765)

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionCyberherbalistView Question on Stackoverflow
Solution 1 - MsbuildvladrView Answer on Stackoverflow
Solution 2 - MsbuildMichael FreidgeimView Answer on Stackoverflow