Notification texts go here Contact Us Buy Now!

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

How to Auto Increment the Version (e.g., “1.0.*”) of a .NET Core Project?

Auto-incrementing the version of a .NET Core project can help you easily track and manage your application's releases. Here's a step-by-step guide to achieve this:

  1. Edit the .csproj File:
    <PropertyGroup>
        <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
        <Deterministic>false</Deterministic>
    </PropertyGroup>
    
  2. Add AssemblyVersion Attribute: In your code, typically in the entry point class, add the following attribute:
    using System.Reflection;
    
    [assembly: AssemblyVersion("1.0.*")]
    
  3. Customize Versioning: For more customization options, refer to this article:
    https://sachabarbs.wordpress.com/2020/02/23/net-core-standard-auto-incrementing-versioning/
  4. Use Visual Studio Extension: For Visual Studio users, consider using the "Automatic Versions" extension:
    https://marketplace.visualstudio.com/items?itemName=PrecisionInfinity.AutomaticVersions

Additional Techniques:

  1. Suppress FileVersion Attribute Generation:
    <PropertyGroup>
        <AssemblyVersion>1.0.*</AssemblyVersion>
        <GenerateAssemblyFileVersionAttribute>false</GenerateAssemblyFileVersionAttribute>
        <Deterministic>false</Deterministic>
    </PropertyGroup>
    
    This allows you to auto-fill the file version with the generated assembly version. (Credits: this answer.)
  2. Generate Build Number: Use the following code to generate the build number in the format "Year.Month.Day.incremental":
    <VersionSuffix>$([System.DateTime]::UtcNow.ToString(yyyy.MM.dd.mmff))</VersionSuffix>
    <AssemblyVersion Condition=" '$(VersionSuffix)' == '' ">0.0.0.1</AssemblyVersion>
    <AssemblyVersion Condition=" '$(VersionSuffix)' != '' ">$(VersionSuffix)</AssemblyVersion>
    <Version Condition=" '$(VersionSuffix)' == '' ">0.0.1.0</Version>
    <Version Condition=" '$(VersionSuffix)' != '' ">$(VersionSuffix)</Version>
    
    <GenerateAssemblyFileVersionAttribute >false</GenerateAssemblyFileVersionAttribute >
    <GeneratePackageOnBuild>true</GeneratePackageOnBuild>
    <GenerateAssemblyInfo>true</GenerateAssemblyInfo>
    <Deterministic>false</Deterministic>
    <GenerateAssemblyTitleAttribute>true</GenerateAssemblyTitleAttribute>
    <GenerateAssemblyConfigurationAttribute>true</GenerateAssemblyConfigurationAttribute>
    <GenerateAssemblyCompanyAttribute>true</GenerateAssemblyCompanyAttribute>
    <GenerateAssemblyProductAttribute>true</GenerateAssemblyProductAttribute>
    <GenerateAssemblyCopyrightAttribute>true</GenerateAssemblyCopyrightAttribute>
    <GenerateAssemblyVersionAttribute>true</GenerateAssemblyVersionAttribute>
    <GenerateAssemblyInformationalVersionAttribute>true</GenerateAssemblyInformationalVersionAttribute>
    

By following these methods, you can easily auto-increment the version of your .NET Core project and streamline your release management process.

Post a Comment

Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.
Site is Blocked
Sorry! This site is not available in your country.