Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dotnet pack with nuspec file does not set PackageVersion from csproj #6636

Closed
livarcocc opened this issue Mar 2, 2018 · 6 comments
Closed

Comments

@livarcocc
Copy link

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

@livarcocc
Copy link
Author

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

@KevReed
Copy link

KevReed commented May 2, 2018

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

@nkolev92
Copy link
Member

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.

@nkolev92 nkolev92 added Style:PackageReference Resolution:ByDesign This issue appears to be ByDesign and removed Triage:Investigate labels Nov 30, 2018
@nkolev92
Copy link
Member

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

@NivagL
Copy link

NivagL commented Sep 12, 2019

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?

@nkolev92
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants