Search code examples
c#.netasp.net-core.net-coreversioning

How to auto increment the version (eg. “1.0.*”) of a .NET Core project?


In the old .NET framework, you could set the [assembly: AssemblyVersion("1.0.*")] and the compiler would auto-increment the version.

With .NET core, I've tried all sorts of things, but I can't get it to auto-increment.

  • I've added <Deterministic>False</Deterministic> and <AssemblyVersion>1.0.*</AssemblyVersion> to the .csproj per similar question. The code compiles but the version stays the same
  • I've tried the same thing but with <Version>1.0.*</Version> tag as described here. This actually set the product version to 1.0.* (with the asterisk).
  • I've set the Assembly Version in the Property Properties/Package page. Doesn't seem to do anything either.

None of it seems to work. Am I missing something simple? This is just a standard .NET Core Web Project.


Solution

  • One simple way I did it previously is by reading the current version and increasing it by one, so you get the current version and increment by one using the command line.

    With that said, it is possible to do the following for the .net core project:

    In your .csproj file, you add the following:

    <PropertyGroup>
        <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
        <Deterministic>false</Deterministic>
    </PropertyGroup>
    

    In your code, for instance, in your entry point class, add the following:

    using System.Reflection;
    
    [assembly: AssemblyVersion("1.0.*")]
    

    When you build the code, it will get a version like 1.0.8419.40347.

    enter image description here

    To make more customization, check this article: https://sachabarbs.wordpress.com/2020/02/23/net-core-standard-auto-incrementing-versioning/

    In addition, I added this link:

    Equivalent to AssemblyInfo in dotnet core/csproj

    And I use this exertion as well for Visual Studio:

    https://marketplace.visualstudio.com/items?itemName=PrecisionInfinity.AutomaticVersions