Search code examples
msbuildazure-pipelines.net-standardgitversion

Package Version not updating under VSTS Build and .NET Standard


I'm building a .NET Standard component using VSTS-Build and GitVersion. And because its .NET Standard I'm having to use msbuild /t:pack instead of the nuget pack step.

This has resulted in the package version number always being 1.0.0 which I assume means that "PackageVersion" isn't being set. The GitVersion documentation says:

the following MSBuild properties are set when UpdateVersionProperties is true

but there doesn't appear to be an option for that.

Anyone know how to get this to work?

Project file:

enter image description here

I changed 2 things from a working build definition, I disabled the Nuget Pack step and I added "/t:pack" as an msbuild argument in the Visual Studio Build step.

Nuspec file.

enter image description here


Solution

  • You should set the GitVersion task ahead of MSBuild task. And it will generate nuget package version with 1.1.0. But it won't update the new version (1.1.0) in your source code, so when you build once again, you will always get the nuget package version 1.1.0.

    And there has another way to generate nuget packages and specify package version as you need. Detail build definition as below:

    • .NET Core task with command restore: specify the path to .csproj.
    • .NET Core task with command build: specify the path to .csproj.
    • .NET Core task with command pack: specify the path to .csproj and the package version (/p:PackageVersion) as you need.

    enter image description here

    To use Gitversion variables for nuget package, you just need to add the argument /p:PackageVersion=$(GitVersion.Major).$(GitVersion.Minor).$(GitVersion.Patch) in .NET Core pack task.

    enter image description here

    The variables $(GitVersion.Major), $(GitVersion.Minor) and $(GitVersion.Patch) are auto generated after executing GitVersion task.