sdk icon indicating copy to clipboard operation
sdk copied to clipboard

dotnet build parameters (-p) don't work when joined by semicolon (;) in dotnet 6.0.400

Open GSonofNun opened this issue 2 years ago • 4 comments

Describe the bug

Using multiple MSBuild parameters joined by a semicolon in a dotnet build command don't work anymore in dotnet 6.0.400.

To Reproduce

Executing the following command doesn't work anymore:

dotnet build -p:propertyA=valueA;propertyB=valueB

But changing it to this does:

dotnet build -p:propertyA=valueA -p:propertyB=valueB

In my case, the command:

dotnet build -p:Version=1.1.1.1;AdditionalConstants=Beta

resulted in the following error:

Error NETSDK1018: Invalid NuGet version string: '1.1.1.1;AdditionalConstants=Beta'.

Exceptions (if any)

N/A

Further technical details

  • Using dotnet version 6.0.400 (previously worked in version 6.0.302)
  • Command being executed as part of an Azure DevOps build pipeline

GSonofNun avatar Aug 09 '22 20:08 GSonofNun

can confirm this too. as a workaround i found out that comma (",") works as a separator, but semicolon (";") does not.

For us this breaks the "pack" task (and a few others) in Azure Devops Pipelines, as they use semicolon as a seperator (and we can't change that)

horihel avatar Aug 10 '22 08:08 horihel

We have also this problem since updating to 6.0.400 with the dotnet build command. Workaround with using "," instead of ";" worked for us.

ThomasTosik avatar Aug 10 '22 09:08 ThomasTosik

We have the same error on our azure-devops pipelines. We reverted to dotnet 6.0.302 for the time being as a workaround

moejoe avatar Aug 10 '22 11:08 moejoe

This was likely introduced in https://github.com/dotnet/sdk/pull/26204, which itself was fixing a regression.

We should extend the testing matrix for MSBuild property forwarding and cover this case, which is fairly unique among CLI arguments: MSBuild allows semicolon or comma-delimited lists of key/value pairs.

In the meantime there are a few workarounds if you want to remain on the latest 6.0.400 version:

  • use commas as your delimiter instead of semicolons in a single -p option
  • specify multiple -p options, each one containing a single key/value pair

baronfel avatar Aug 10 '22 12:08 baronfel

We have also faced this problem, although in a slightly different way: it is now impossible to specify multiple values for a single property using ; delimeter.

In our projects, we use -p:TargetFrameworks=\"net5.0;net6.0\" which worked flawlessly, until that specific version of dotnet.

However, specifying <TargetFrameworks>net6.0;net5.0</TargetFrameworks> directly in csproj still works as intended.

HolyPrapor avatar Aug 18 '22 07:08 HolyPrapor

I'm seeing the same problem as @HolyPrapor, with the RuntimeIdentifiers property.

Setting it on the command line like this:

dotnet build '/p:RuntimeIdentifiers="osx-arm64;osx-x64"'

doesn't work anymore, because it ends up being passed as a string (instead of an array of strings) to the RuntimeIdentifiers property of the ProcessFrameworkReferences task.

The difference seems to be that the property is now quoted when passed to msbuild:

--property:RuntimeIdentifiers=osx-arm64%3Bosx-x64

rolfbjarne avatar Aug 18 '22 10:08 rolfbjarne

I would like to emphasize that this causes build failures from one day to another in Azure Pipelines because of the way the DotNetCoreCLI task runs the dotnet command. In our case we run dotnet using arguments like these:

- task: DotNetCoreCLI@2
  inputs:
    command: pack
    configuration: $(buildConfiguration)
    packagesToPack: '**/*.csproj'
    buildProperties: 'InformationalVersion=Foo'

And it fails because under the hood dotnet will be run using this argument:

dotnet pack [...] /p:Configuration=Release;InformationalVersion=Foo

Which since 6.0.400 will lead to the build configuration actually being Release;InformationalVersion=Foo instead of Release.

As you can see we don't specify semicolons or commas anywhere and we don't have a way to specify multiple -p options on the command line. I can see that this may need to be fixed in Azure Pipelines instead but I suspect this combination to lead to build failures all over the place.

X-Celcius avatar Aug 22 '22 11:08 X-Celcius

@baronfel this is fixed in .NET SDK 6.0.401 https://dotnet.microsoft.com/en-us/download/dotnet/6.0

justinswork avatar Sep 13 '22 20:09 justinswork

Yep! This just wasn't closed when the linked PR merged. I'll do so now.

baronfel avatar Sep 13 '22 20:09 baronfel

I'm still seeing the same issue with 6.0.401. When passing in:

dotnet pack foo.csproj --no-build --no-restore  -o C:\tmp -c Release /p:NuspecFile=foo.nuspec -p:NuspecProperties=\"Version=1.0.41566;configuration=Release;Id=Foo;Description=Foo\"

I receive the following error: C:\Program Files\dotnet\sdk\6.0.401\Sdks\NuGet.Build.Tasks.Pack\build\NuGet.Build.Tasks.Pack.targets(221,5): error : An error occured while trying to parse the value '1.0.41566;configuration=Release;Id=Foo;Description=Foo' of property 'version' in the manifest file. [foo.csproj] C:\Program Files\dotnet\sdk\6.0.401\Sdks\NuGet.Build.Tasks.Pack\build\NuGet.Build.Tasks.Pack.targets(221,5): error : '1.0.41566;configuration=Release;Id=Foo;Description=Foo' is not a valid version string. (Parameter 'value') [foo.csproj]

henryzhao95 avatar Sep 14 '22 07:09 henryzhao95

@henryzhao95 the issue you're seeing might be related to #15482. Otherwise do you need to escape the quotes around your NuspecProperties? I would just try removing the backslashes

dotnet pack foo.csproj --no-build --no-restore -o C:\tmp -c Release /p:NuspecFile=foo.nuspec -p:NuspecProperties="Version=1.0.41566;configuration=Release;Id=Foo;Description=Foo"

justinswork avatar Sep 14 '22 12:09 justinswork