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

MSBuild targets are not applied to generated project.assets.json for project references when packaging from Visual Studio 2017 #6037

Closed
soen opened this issue Oct 16, 2017 · 2 comments
Labels
Functionality:Pack Resolution:Duplicate This issue appears to be a Duplicate of another issue Triage:Investigate
Milestone

Comments

@soen
Copy link

soen commented Oct 16, 2017

Details about Problem

NuGet product used (NuGet.exe | VS UI | Package Manager Console | dotnet.exe):
VS UI

NuGet version (x.x.x.xxx):
4.3.0.4406
4.4.0

dotnet.exe --version (if appropriate):
2.0.0
2.0.2

VS version (if appropriate):
Visual Studio 2017 15.3.5
Visual Studio 2017 15.4.0

OS version (i.e. win10 v1607 (14393.321)):
win10 (10.0.15063 Build 15063)

Worked before? If so, with which NuGet version:
N/A

Detailed repro steps so we can see the same problem

  1. Open the sample project TestSetVersion.zip

  2. Pack the project named ProjectC from VS, by right-clicking on the project in the Solution Explorer and selecting Pack

  3. Once packed, open the file TestSetVersion\ProjectC\bin\Debug\ProjectC.1.2.3-r12345.nupkg (i.e. using NuGet Package Explorer)

  4. Verify that the package contains two dependencies with the following versions; ProjectA >= 1.2.3.r12345 and ProjectB >= 1.2.3.r12345

  5. Remove the \bin and \obj output folders from TestSetVersion\ProjectC\

  6. Open the file TestSetVersion\Directory.Build.props, and comment out the target named BeforeGenerateNuspec

  7. Pack the project named ProjectC from VS

  8. Once packed, open the file TestSetVersion\ProjectC\bin\Debug\ProjectC.1.2.3-r12345.nupkg (i.e. using NuGet Package Explorer)

  9. Verify that the package contains two dependencies with the following (incorrect) versions; ProjectA >= 1.0.0 and ProjectB >= 1.0.0

Based on the above it seems that when a project (ProjectC) is referencing other projects (ProjectA and ProjectB), in the same solution, the versions of the referenced projects will not be set to the version provided by the given SetVersion target. This behaviour only seem to occur when packaging the project from inside VS, as calling either MSBuild (msbuild \t:restore \t:pack) or the .NET Core CLI (dotnet pack) directly will produce a package for ProjectC that contains dependencies to ProjectA and ProjectB with the version set via the SetVersion target.

It is expected that the file project.assets.json is generated with the correct version for the project it belongs to, and also with correct versions for PackageReferences.

Do note that the target BeforeGenerateNuspec and the inline task FixProjectAssetsJson is indeed a workaround, since it is not fully clear how to use MSBuild targets, since the Restore Target from NuGet doesn’t seem to be executed from VS, and there seems to be no clear public targets available for before or after generating the project.assets.json file.

@jainaashish
Copy link

even project.assets.json also has 1.0.0 version for both packageA and packageB and if i'm not wrong pack is picking these versions for dependencies. I think SetVersion is not being called with target.

@emgarten do you have any comment here?

@emgarten emgarten added this to the 4.6 milestone Nov 9, 2017
@emgarten emgarten added the Resolution:Duplicate This issue appears to be a Duplicate of another issue label Nov 9, 2017
@emgarten
Copy link
Member

emgarten commented Nov 9, 2017

Duplicate of #4790

@emgarten emgarten marked this as a duplicate of #4790 Nov 9, 2017
@emgarten emgarten closed this as completed Nov 9, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Functionality:Pack Resolution:Duplicate This issue appears to be a Duplicate of another issue Triage:Investigate
Projects
None yet
Development

No branches or pull requests

3 participants