msbuild: Unable to pass in Property values containing a semicolon or comma in .Net Core MSBuild
In corefx repo, we pass in a special property in our outerloop jenkins runs that contains a colon ‘;’ on the property name. With Full MSBuild, the behavior is that given the colon is found inside a quoted string, then it just assumes that the colon is part of the string. However, in .Net Core the behavior is different, since what it tries to do is to use the colon as the end of the string, and assumes that everything after the colon is a different switch. For example, if you have the following target:
<Target Name="TestTarget">
<ItemGroup>
<IParam Include="$(Param)" />
</ItemGroup>
<Message Text="The param passed was: @(IParam)" />
</Target>
You get the following when using full msbuild:
msbuild build.proj /p:Param="Hello;World" /t:TestTarget
Project "C:\Users\joperezr\Desktop\repo\corefx\build.proj" on node 1 (TestTarget target(s)).
TestTarget:
The param passed was: Hello;World
This is the result when running the same target in .Net Core MSBuild:
Corerun.exe MSBuild.exe build.proj /p:Param="Hello;World" /t:TestTarget
MSBUILD : error MSB1006: Property is not valid.
Switch: World
About this issue
- Original URL
- State: open
- Created 8 years ago
- Reactions: 8
- Comments: 20 (9 by maintainers)
Links to this issue
Commits related to this issue
- Properly escape the /p value See https://github.com/dotnet/msbuild/issues/471#issuecomment-366268743 — committed to dotnet/sdk by akoeplinger 3 years ago
- Escape quote Ref https://github.com/dotnet/msbuild/issues/471 — committed to SlashNephy/Divination.Template by SlashNephy 3 years ago
- Escape quote Ref https://github.com/dotnet/msbuild/issues/471 — committed to SlashNephy/Divination.Template by SlashNephy 3 years ago
@danmosemsft found a very nice workaround in https://github.com/Microsoft/msbuild/issues/2999#issuecomment-366101535
Semicolon
;
is%3B
.Just to give an update, we’re not sure exactly how to fix this quite yet. An easy workaround is to escape the quotes:
msbuild build.proj /p:Param=\"Hello;World\" /t:TestTarget
The issue is here. We previously used Environment.CommandLine which kept the quotes, the string array does not. Since Environment.CommandLine is not supported in .NET Core right now, we will have to modify our logic to handle this case.
Have you tried something like this ‘/p:CodesignKey=“iPhone Distribution: Some Company, LLC”’
Helped me.
I’m having this same issue. However escaping the string doesn’t help. I am using Powershell if that matters.
I still get the “property is not valid” error.
I am using the .NET Core SDK 2.0 to build and have verified that is what it is using with the dotnet --version command.
msbuild command
That is working in Powershell
dotnet command
In powershell, that is working for dotnet command
In cmd console, that is working for dotnet command
@rainersigwald , There is a variation between dotnet command and msbuild command.
Unfortunately,
%3B
does not get split into items in an ItemGroup like a normal semicolon (even though it appears like one).Workaround for PowerShell seems to be:
(slash and backtick before quotes, backtick before semicolon)
Alternative workaround would be to keep whole thing in single quote
'/p:Param="Hello;World'
.We get same problem with latest Xamarin on Mono: msbuild with parameter
/p:CodesignKey="iPhone Distribution: Some Company, LLC"
fails with exactly same error. But works with'/p:CodesignKey="iPhone Distribution: Some Company, LLC"'