Setting the version number for .NET Core projects - CSPROJ - not JSON projects
Solution 1:
You can override any property from the command line by passing /p:PropertyName=Value
as arguments to dotnet restore
, dotnet build
and dotnet pack
.
Currently, Version composition works as this:
If Version
is unset, use VersionPrefix
(defaults to 1.0.0 if unset) and - if present - append VersionSuffix
.
All other version are then defaulted to whatever Version
is.
So for example you can set <VersionPrefix>1.2.3</VersionPrefix>
in your csproj and then call dotnet pack --version-suffix beta1
to produce a YourApp.1.2.3-beta1.nupkg
(if you have project reference that you want the version suffix to be applied to as well, you need to call dotnet restore /p:VersionSuffix=beta1
before that - this is a known bug in the tooling).
Of course, you can use custom variables as well, see this GitHub issue for a few examples.
For a complete reference of supported assembly attributes, i suggest looking at the source code of the build logic here (the values surrounded with $()
are the properties used).
And since i'm already talking about the source, this is the logic that composes the version and a few other properties.
Solution 2:
dotnet build /p:AssemblyVersion=1.2.3.4
Does that work for you?