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?
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With