Auto Versioning in Visual Studio 2017 (.NET Core)

Jason H picture Jason H · Mar 25, 2017 · Viewed 73.3k times · Source

I have spent the better part of a few hours trying to find a way to auto-increment versions in a .NETCoreApp 1.1 (Visual Studio 2017).

I know the the AssemblyInfo.cs is being created dynamically in the folder: obj/Debug/netcoreapp1.1/

It does not accept the old method of: [assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.*")]

If I set the project to package I can set versions there but this seems to be used to build the AssemblyInfo.cs file.

My question is, has anyone figured out how to control version in .NET Core (or .NETStandard for that matter) projects.

Answer

Michael Freidgeim picture Michael Freidgeim · Oct 28, 2017

Add <Deterministic>False</Deterministic> inside a <PropertyGroup> section  of .csproj

The workaround to make AssemblyVersion * working is described in “Confusing error message for wildcard in [AssemblyVersion] on .Net Core #22660”

Wildcards are only allowed if the build is not deterministic, which is the default for .Net Core projects. Adding <Deterministic>False</Deterministic> to csproj fixes the issue.

The reasons why .Net Core Developers consider Deterministic Builds beneficial described in http://blog.paranoidcoding.com/2016/04/05/deterministic-builds-in-roslyn.html and Compilers should be deterministic: same inputs generate same outputs #372

However if you are using TeamCity, TFS or other CI/CD tool, it's probably better to keep the version number controlled and incremented by them and pass to build as a parameter (as it was suggested in other answers) , e.g.

msbuild /t:build /p:Version=YourVersionNumber /p:AssemblyVersion=YourVersionNumber

Package number for NuGet packages

msbuild /t:pack /p:Version=YourVersionNumber