Home: dotnet pack with nuspec file does not set PackageVersion from csproj

Created on 2 Mar 2018  路  6Comments  路  Source: NuGet/Home

_From @maciejjarzynski on March 2, 2018 9:49_

Steps to reproduce

When running dotnet pack on the project which also has .nuspec file specified, and the version is being set only in .csproj PackageVersion setting, while in nuspec it is a variable $version$, it fails to create package.

Csproj:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <Version>1.1.1</Version>
    <PackageVersion>1.1.1</PackageVersion>
    <NuspecFile>TestAssembly.nuspec</NuspecFile>
    <TargetFramework>netstandard2.0</TargetFramework>    
  </PropertyGroup>
</Project>

Nuspec:

<?xml version="1.0"?>
<package >
  <metadata>
    <id>TestAssembly</id>
    <version>$version$</version>
    <authors>Test</authors>
    <description>Description</description>
  </metadata>
</package>

Command to run:
dotnet pack

Expected behavior

Creating package with version provided in .csproj file.

Actual behavior

An error during dotnet pack:

C:\Program Files\dotnet\sdk\2.1.4\Sdks\NuGet.Build.Tasks.Pack\build\NuGet.Build.Tasks.Pack.targets(204,5): error : Value cannot be null or an empty string. [...\TestAssembly.csproj]
C:\Program Files\dotnet\sdk\2.1.4\Sdks\NuGet.Build.Tasks.Pack\build\NuGet.Build.Tasks.Pack.targets(204,5): error : Parameter name: value [...\TestAssembly.csproj]

Environment data

dotnet --info output:
.NET Command Line Tools (2.1.4)

Product Information:
Version: 2.1.4
Commit SHA-1 hash: 5e8add2190

Runtime Environment:
OS Name: Windows
OS Version: 10.0.16299
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\2.1.4\

Microsoft .NET Core Shared Framework Host

Version : 2.0.5
Build : 17373eb129b3b05aa18ece963f8795d65ef8ea54

_Copied from original issue: dotnet/cli#8717_

Pack ByDesign PackageReference

Most helpful comment

Adding <NuspecProperties>version=$(Version)</NuspecProperties> to the csproj seems to work

All 6 comments

@rohit21agrawal If this is something that the SDK should be setting but it is not, then please, comment and re-activate the original issue.

Adding <NuspecProperties>version=$(Version)</NuspecProperties> to the csproj seems to work

This is by design.
NuGet will not read the PackageVersion, as "token" replacements are what's being done in the nuspec.

Using NuspecProperties is the correct approach.

Furthermore the error messages have since been improved, so it should be easier to diagnose.

This is by design.
NuGet will not read the PackageVersion, as "token" replacements are what's being done in the nuspec.

Using NuspecProperties is the correct approach.

My package contains many projects. The version is independent of any csproj. Where is the package version suppose to be?

NuspecProperties is an MSBuild property, so it can be defined/amended as needed with MSBuild.
You can define some of the properties in some shared targets.

Note that this is only the case if you are using dotnet pack with a nuspec file.

Was this page helpful?
0 / 5 - 0 ratings