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)

Commits related to this issue

Most upvoted comments

@danmosemsft found a very nice workaround in https://github.com/Microsoft/msbuild/issues/2999#issuecomment-366101535

Note I discovered a workaround; MSBuild escaping works here. Comma is %2c so

dan@danmose2:~/dotnetU$ dotnet msbuild  /p:"aaa=bbb,ccc" /v:diag | grep "ccc"
Switch: ccc
dan@danmose2:~/dotnetU$ dotnet msbuild  /p:"aaa=bbb%2cccc" /v:diag | grep "ccc"
/usr/share/dotnet/sdk/2.1.3/MSBuild.dll /Logger:Microsoft.DotNet.Tools.MSBuild.MSBuildLogger,/usr/share/dotnet/sdk/2.1.3/dotnet.dll /m /p:aaa=bbb%2cccc /v:m /v:diag ./dotnetU.csproj
                   aaa = bbb,ccc

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.

[string]$frameworks_to_test = "netcoreapp1.0,net451"

$testFrameworks = $frameworks_to_test.Replace(',', ';')

			&dotnet msbuild $solutionFile /t:Build `
				/p:Configuration=$configuration `
				/p:AssemblyVersion=$assemblyVersion `
				/p:InformationalVersion=$pv `
				/p:Product=$product_name `
				/p:Company=$company_name `
				/p:Copyright=$copyright `
				/p:TestFrameworks=\"$testFrameworks\"

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

msbuild "/t:restore" "/t:build" "/p:LibraryFrameworks=`"net6.0;net7.0`"" 
# note: backtick and quote

dotnet command

In powershell, that is working for dotnet command

## as said by @JVimes 
dotnet build "/p:LibraryFrameworks=\`"net6.0;net7.0\`""
##note:  slash and backtick before quotes. (NO NEED for backtick before semicolon)

In cmd console, that is working for dotnet command

dotnet build "/p:LibraryFrameworks=""net6.0;net7.0"""
::note: use double quote , and quote all string "/p......."

@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:

/p:Param=\`"Hello`;World\`"

(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"'