Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass path with spaces and trailing backslash to MSBuild as property

When I try to pass some directory path into MSBuild script as follows:

MSBuild.exe myproj.proj /p:DirPath="C:\this\is\directory\"

And in .proj file I use it as

<PropertyGroup>
  <FilePath>$(DirPath)file.txt</FilePath>
<PropertyGroup>

Then MSBuild composes FilePath as c:\this\is\directory"file.txt. If I pass DirPath without quotes but with trailing slash (/p:DirPath=c:\this\is\directory\) or without trailing slash but with quotes (/p:DirPath="c:\this\is\directory\") then everything works fine.

What can be done to allow passing directory path with trailing slash (it would be more convenient) and in quotes (since path can contain spaces)? Or is it a bug in MSBuild and I should use some workaround, like removing trailing backslash upon passing it into msbuild?

like image 977
Dmitrii Lobanov Avatar asked Apr 25 '13 07:04

Dmitrii Lobanov


1 Answers

It is because of the way the property is being set on the command line. MSBuild is adding the " to the end of the value because of the last '\' and therefore " is appended to the end of the string path.

Add a extra \ when setting the value from the command line and the string will append the backslash for you as intended or not place the " on the end.

MSBuild.exe myproj.proj /p:DirPath="C:\this\is\directory\\"

The value is then : C:\this\is\directory\file.txt

Another soulution is you can put this function in your MSBuild project to replace the " :

<PropertyGroup>
    <DirPath>$(DirPath.Replace('"',""))</DirPath>
</PropertyGroup>
like image 76
SoftwareCarpenter Avatar answered Nov 04 '22 02:11

SoftwareCarpenter