How to Auto Increment Version Number in Visual Studio

By FoxLearn 1/17/2025 9:58:07 AM   33.95K
In Visual Studio, you can automatically increment the version number of your assembly by following these steps.

To increment the assembly version automatically in a .NET project, you can use several methods, including using wildcards or integrating a custom MSBuild script.

Using Wildcards for Build and Revision Numbers

In your AssemblyInfo.cs file, you can set the version as follows:

// c# assembly version auto increment
[assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyFileVersion("1.0.*")]

With 1.0.*, the * will allow MSBuild to automatically generate the build number and revision number based on the current date and time.

Every time you build, the version will be incremented.

  • The AssemblyVersion will follow the pattern 1.0.<Build Number>.<Revision Number>.
  • The AssemblyFileVersion will also have the same pattern, but it can be displayed differently in the file properties of the application.

Using a Custom MSBuild Target to Increment the Version

If you need more control over the version incrementing process, such as incrementing the version in a specific way, you can use an MSBuild target to do so.

You can add this logic in your .csproj file.

For example, you can modify the version information in your .csproj file by opening the .csproj file of your project.

Then, add the following MSBuild target to automatically increment the version number.

<PropertyGroup>
  <!-- Define the base version and build increment -->
  <VersionPrefix>1.0.0</VersionPrefix>  <!-- Base version -->
  <Version>$(VersionPrefix).$(Build.BuildId)</Version>  <!-- Append build ID -->
</PropertyGroup>

<Target Name="BeforeBuild">
  <Message Text="Incrementing assembly version to $(Version)" />
  <!-- Optionally, update AssemblyInfo.cs or other version-related files -->
</Target>

In this example:

  • VersionPrefix defines the base version (1.0.0).
  • Build.BuildId is a unique identifier for each build, and it auto-increments with every build.

In Visual Studio, you can set up auto-incrementation for version numbers using third-party tools and plugins available that integrate with Visual Studio and automatically manage version numbers for you.

How to auto increment version in Visual Studio

Here's how to increase version .net automatically in Visual Studio 2017 2019 2022 using the Build Version Increment Add-In extension. This extension help you increments the version of an assembly or assemblies based on the specified configuration.

Open your Visual Studio, then select Tools => Extensions and Updates...=> Search for 'increment version', then download and install 'Build Version Increment Add-In' into your Visual Studio.

build version increment add-in

How to use Build version increment add-in (Visual Studio 2022 auto increment version)

After completing the installation, reopen your Visual Studio you will see the Add-in (Visual Studio Increment Version number on build) in the tools menu.

Selecting Tools => Build Version Increment => Settings

visual studio increment version number on build

Visual Studio Version Numbers

This extension allows Visual Studio to increment the version number on build.

Auto-increment versioning is a mechanism that automatically increments the version number with every new build. The version number generally follows a format such as Major.Minor.Build.Revision:

Each version of any application has 4 parameters: Major, Minor, Build, Revision.

For example: (1.0.0.0)

- The first number describes the major version.

- The second number describes the minor version.

- The 3rd number describes the order of the build version.

- The last number describes the revised version.

You can configure visual studio set version number, which allows you to increase the assembly version via the Versioning Style property.

 visual studio auto increment version

If everything is correct, after each rebuild of your project, you should see the assembly version automatically increase according to the configuration you have installed.

By using Visual Studio auto increment version capabilities, developers can automate the process of incrementing the build or revision number, ensuring that each build gets a unique version number without the need for manual intervention.

VIDEO TUTORIAL