Setting the version number for .NET Core projects - CSPROJ - not JSON projects
dotnet build /p:AssemblyVersion=1.2.3.4
Does that work for you?
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.
In my case, the main key was /property:Version=1.2.3.4
. And the following command line did the job:
dotnet build SolutionName.sln -c Release /property:Version=1.2.3.4
This will override Assembly default version.
Update
So in addition just to clarify this in a practical use case of software release.
For instance when you publish a software you can set File version and Product version as mentioned here.
lets take an example:
dotnet publish .\ProjectFolder\Project.csproj -r win-x64 /p:PublishSingleFile=true /p:IncludeNativeLibrariesForSelfExtract=true --self-contained true -o ReleaseFolderName -c Release /p:AssemblyVersion=1.2.3.4 /p:Version=1.2.3.4-product-version
will publish software, when right click on software and click on Details, you get following picture: