Changing the version for dotnet pack does not change the dependency version
Nobody has claimed this yet.
- Dominant language
- HTML
- Stars
- 1.6k
- Forks
- 276
- Avg merge
- 6d 1h
- Merged PRs (30d)
- 1
Description
When defining a version for a package inside a custom target the package version and the reference version inside the package generated through dontet pack are mismatched.
I change the version and packVersion within a Target running before GenerateNuSpec (in Directory.Build.targets) like this:
<Target Name="SetVersion" BeforeTargets="GenerateNuspec">
<PropertyGroup>
<Version>$(MyProjectSpecificCalculatedVersion)</Version>
<PackageVersion>$(MyProjectSpecificCalculatedVersion)</PackageVersion>
</PropertyGroup>
</Target>
This is picked up during pack and correctly set as the version for the nupkg filename and inside the nupkg as the nuspec-version, as expected.
When referencing project B from project A both are packed with the correct version but the dependency inside the nupkg for project B is always set to 1.0.0
It seems the version used is whatever is written inside the obj/project.assets.json which is generated during dotnet restore. But even if I set BeforeTargets="Restore" that version is never populated correctly.
Is there another way to write that target in order to have the same version for both the package and the reference?
This is using dotnet version 3.1.300, a minimal reproduction is attached:
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Use the attached DotNetPackTest.zip to reproduce the mismatch with dotnet pack and restore. Start with Directory.Build.targets, the SetVersion target, GenerateNuspec, and obj/project.assets.json; compare the package version with the project dependency version. Done means the generated package and its dependency reference use the same calculated version.
Written by the indexing model from the issue text.
Assessment
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100