sdk: The dotnet pack doesn't work together with -p:NuspecProperties when multiple properties provided

When calling the

dotnet pack project.csproj -p:NuspecFile=project.nuspec -p:NuspecProperties="version=11.0.0;year=2021" --verbosity quiet --output c:/temp

command to pack a NuGet package providing multiple properties (version, year), only the first one is replaced in nuspec file with the provided value. Others are resolved as an empty string.

project.csproj file image

project.nuspec file image

nuspec file in resulted package image

Is there anything I am missing or there might be a bug in passing the properties?

Thanks.

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Reactions: 2
  • Comments: 16 (7 by maintainers)

Most upvoted comments

It looks like this approach works as you described.

The thing is I followed the documentation here: https://docs.microsoft.com/en-us/nuget/reference/msbuild-targets#packing-using-a-nuspec.

Where there is this statement: NuspecProperties: a semicolon-separated list of key=value pairs. Due to the way MSBuild command-line parsing works, multiple properties must be specified as follows: -p:NuspecProperties=“key1=value1;key2=value2”.

And since the values of the properties are in my case dynamically populated (evaluated as part of the build pipeline), I wanted them to be provided as dotnet pack arguments.

For now, I use plain string replace to provide the values to the nuspec file as a workaround.

Hopefully, it makes sense.

When I reverse the order it’s the same behavior - only the first parameter is replaced - the year in this case. SPlitting the properties this way:

dotnet pack project.csproj -p:NuspecFile=project.nuspec -p:NuspecProperties="version=11.0.0" -p:NuspecProperties="year=2021" --verbosity quiet --output c:/temp

doesn’t help either. Unfortunately, the second argument value overrides the first one, so in this case, only the ‘year’ is replaced (Actually the pack fails because the version is empty since it is not replaced with the correct value).

So sadly nothing from the provided workarounds work.

cc : @baronfel The solution that works for me is to use either update the .csproj or create a dynamic Directory.Build.props file (good for pipeline builds) and then add the nuspec properties NuspecFile , NuspecProperties there

<Project> <PropertyGroup> ....... <NuspecFile>app.nuspec</NuspecFile><NuspecProperties>version=$(PackageVersion);dateToday=$(dateToday);releaseName=$(releaseName)</NuspecProperties> </PropertyGroup> </Project>

app.nuspec file <version>$version$</version> ....... <description> ReleaseName :$releaseName$ date : $dateToday$ </description>

Then pass multiple parameters to csproj using below command:- dotnet pack "…\abcd.csproj" /p:PackageVersion=%version% /p:dateToday=%date:~10,4%%date:~4,2%%date:~4,2% /p:releaseName=%releaseName%

In this way I can use multiple Nuspec properties, however still not able to use it from the argument -p:NuspecProperties=… when using dotnet pack command

Facing the same issue. Cannot pass multiple parameters to NuspecProperties

-p:NuspecProperties="version=5.0.3;configuration=Release"

returns

"C:\Program Files\dotnet\sdk\6.0.303\Sdks\NuGet.Build.Tasks.Pack\build\NuGet.Build.Tasks.Pack.targets(221,5): error : An error occured while trying to parse the value '5.0. 3;configuration=Release' of property 'version' in the manifest file."

Just ran into this as well – any plans to fix? If not, I may take a stab at opening a PR to fix this up.

So I decided to try using a .nuspec file to work around this issue, https://github.com/NuGet/Home/issues/3891 , and I ran into this issue of not being able to pass multiple key/value pairs to -p:NuspecProperties. It is especially frustrating because the docs continue to say that this is supported. Are there any plans to fix this?

We are running into exactly the same issue. This issue prevents us from using dotnet pack for packaging based on .nusepc files. It is a bit disappointing that this does not work as advertised on the posted link:

The thing is I followed the documentation here: https://docs.microsoft.com/en-us/nuget/reference/msbuild-targets#packing-using-a-nuspec.

Are there any plans to address this issue?

Does it work if you specify the property in the project?

This can probably be transferred NuGet side if that doesn’t fix it.

MSBuild would interpret the command line to mean that the property NuspecProperties should have the value version=11.0.0;year=2021, but it doesn’t do any more parsing initially, so there’s presumably some parsing afterwards that converts it to real nuspec properties.

Have you tried reversing the order of the parameters (year=2021;version=11.0.0)? Version is given a default value if one isn’t found, whereas year isn’t. That might mean it was looking for version, and year would have to be set separately. Also, I’d try splitting version=11.0.0;year=2021 into two properties initially and seeing if you can pass them separately.