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:
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.
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:
restore
: specify the path to .csproj.build
: specify the path to .csproj.pack
: specify the path to .csproj and the package version (/p:PackageVersion
) as you need.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.The variables
$(GitVersion.Major)
,$(GitVersion.Minor)
and$(GitVersion.Patch)
are auto generated after executing GitVersion task.