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 11 years ago
  • Reactions: 10
  • Comments: 21 (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.

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

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.

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

This was the exact work around for the issue we had. Thank you for posting this. Here is our bash command that we used in our pipeline(our company name has a comma in the signing identity):

‘-p:CodesignKey=“$(APPLE_CERTIFICATE_SIGNING_IDENTITY)”’

- task: Bash@3
  displayName: Build app and publish ipa file
  inputs:
    targetType: inline
    script: dotnet publish --no-restore -r ios-arm64 -c Release -p:ArchiveOnBuild=true -p:ApplicationId=$(AppStore.CFBundleIdentifier) '-p:CodesignKey="$(APPLE_CERTIFICATE_SIGNING_IDENTITY)"' -p:CodesignProvision=$(APPLE_PROV_PROFILE_UUID)

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)

We’ve discussed this at length in team meeting and triage. It seems the core issue here is we have custom parsing logic that differs from the command line parameter parsing logic, and they’re somewhat incompatible and mutually exclusive between .NET Core and full .NET.

In Windows, we get the command line as passed in and parse it. Since this is not available in .NET Core we do something slightly different. Some options:

  1. Modify our parsing logic to be smarter about arg splitting. Since we don’t have to do anything to split them this would likely be easier, but probably not 100% compatible and diverge us more from the full Framework version. Not ideal. I imagine there was also a reason why this was done in this way in the first place, but that might be over optimistic.
  2. Implement platform specific logic to try to get the proper string and use that. This is easy in Windows/cmd.exe, but not so with every platform and command processor out there. I don’t want builds to fail like this in only certain scenarios for something like quotes in the command line.
  3. Try to fix this scenario, recognizing that with the loss of fidelity from the users string -> parsed args there will likely be further issues found in the future.
  4. Do nothing and escape quotes when using the .NET Core version and you need them to appear.

None of these are very good, for now we’re going to stick with option 4. If someone has a better idea please speak up.

Note that Environment.CommandLine isn’t available by design, the issue is here https://github.com/dotnet/coreclr/issues/3103 for the discussion.