David Esteves
David Esteves

Reputation: 1604

Dotnet pack doesn't respect dynamic variables for version attribute

Hey I have been trying to change my csproj to use the .net core style. The project is a class library that I generate a nuget package from. All seems to work fine with the changes if I specify the value as a hard coded value

<Version>1.0.1.1</Version>

However I am trying to use a shared assembly file to drive the version of a few projects in the sln. Which works fine for the dll but not the nuget package it generates. running dotnet pack has the same issue.

I tried a couple things to get this to work but the most surprising seems to be how it ignores variables. e.g.

InitialTargets="SetVersion"

<Target Name="SetVersion">
<PropertyGroup>
  <Version>1.0.1.1</Version>
</PropertyGroup>

<Version>$(Version)</Version>

The dlls generated all have version 1.0.1.1 or whatever the variable is set to. However the nuget package still just generates version 1.0.0.0.

The exact same output if I specify:

<GenerateAssemblyVersionAttribute>false</GenerateAssemblyVersionAttribute>

And let it read the version from the SharedAssembly.cs file. The dlls are the correct version but not the nuget package.

I know I could just specify the version when calling dotnet pack but was hoping to avoid that and have it just happen correctly when running the build from VS

Upvotes: 0

Views: 480

Answers (1)

Set
Set

Reputation: 49789

Try to use <PackageVersion>: this is the MSBuild property so it have to go within a <PropertyGroup> group:

<PropertyGroup>
    <PackageVersion>1.0.1.1</PackageVersion>
</PropertyGroup>

Upvotes: 3

Related Questions