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

Packing project with project dependencies does not include build number in nupkg #7883

Closed
henkmollema opened this issue Mar 9, 2017 · 5 comments

Comments

@henkmollema
Copy link

Steps to reproduce

  1. Create two class library projects (eg. ProjA and ProjB)
  2. Create a project reference from ProjB to ProjA:
<ProjectReference Include="..\ProjA\ProjA.csproj" />
  1. Use this version in the projects:
<VersionPrefix>1.2.0</VersionPrefix>
<VersionSuffix>preview1</VersionPrefix>
<VersionSuffix Condition="'$(VersionSuffix)'!='' AND '$(BuildNumber)' != ''">$(VersionSuffix)-$(BuildNumber)</VersionSuffix>
  1. Create NuGet packages by calling dotnet pack on the solution specifying a build number:
dotnet pack -c Release -o <dir> /property:BuildNumber=123

Expected behavior

A nupkg for ProjB with a dependency to ProjA with version 1.2.0-preview1-123.

Actual behavior

A nupkg for ProjB with a dependency to ProjA with version 1.2.0-preview1.

Environment data

dotnet --info output:

λ dotnet --info
.NET Command Line Tools (1.0.0)

Product Information:
 Version:            1.0.0
 Commit SHA-1 hash:  e53429feb4

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

This behavior changed with the move from project.json to MSBuild. @natemcmaster also mentions this in one of his blog posts about the conversion: http://www.natemcmaster.com/blog/2017/01/19/project-json-to-csproj/ (at the "dependency type" chapter). Neither --version-suffix or /property:BuildNumber works as expected.

This change causes other libraries which in turn reference ProjB to select the lowest (e.g. first) version of ProjA.

Workaround

Not sure if this is a workaround, but when I specify the build number when restoring packages it writes the correct reference in the project.assets.json:

dotnet restore /property:BuildNumber=$buildNumber

When packing the correct version number for dependencies will be used now.

The same behavior is achieved when settings the BuildNumber environment variable.

@qrli
Copy link

qrli commented Mar 9, 2017

Not only with version suffix, also with non-prerelease versions.

dotnet pack -c Release /property:Version=1.0.1

The result nupkg is v1.0.1 but dependencies via project referenced is always 1.0.0. It seems now cli only read the Version property from referenced .csproj file but do not honor the multiple project/package relationship, unlike the old project.json tooling.

@nrandell
Copy link

nrandell commented Mar 9, 2017

I've seen the same, but by setting the environment variables VERSION_PREFIX and VERSION_SUFFIX everything appears to be ok.

I think it is in the restore stage that this is needed. If you look in project.assets.json inside the obj directory, you can see the version it is using. That appears to be copied across to the nuspec file on packing. After I set the correct VERSION_PREFIX and VERSION_SUFFIX environment variables, the project.assets.json file has the correct versions, so does the nuspec files.

@henkmollema
Copy link
Author

henkmollema commented Mar 9, 2017

@nrandell you're right. When I specify the build number when restoring (e.g. dotnet restore /property:BuildNumber=$buildNumber or setting the environment variable) the project.assets.json contains references to the correct version numbers and the NuGet package contains the correct dependencies.

I've updated the first post with above workaround.

@natemcmaster
Copy link
Contributor

This is a duplicate of NuGet/Home#4337. This workaround is also mentioned in that issue.

@henkmollema
Copy link
Author

I see, thanks. 👍

@msftgits msftgits transferred this issue from dotnet/cli Jan 31, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants