Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatically increment version number in ASP .NET Core

I'm developing a REST API using ASP.NET Core and want the version number to be automatically incremented. This used to be easily by the following pattern in the AssemblyInfo file: [assembly: AssemblyVersion("1.6.*")].

I have read a couple of suggestions to use gulp or other third party tools to accomplish this, like the answer here

But do I really need a third party tool to get automatically increased version number? Is there no longer a built-in feature to support this? It feels like I'm missing something here.

like image 615
Janni Kajbrink Avatar asked Jan 04 '17 09:01

Janni Kajbrink


People also ask

Can I automatically increment the file build version when using Visual Studio?

By default, Visual Studio automatically increments the Revision number of the Publish Version each time you publish the application. You can disable this behavior on the Publish page of the Project Designer.

How do I change the DLL version number in Visual Studio?

Open the project's Property Pages dialog box. For details, see Set C++ compiler and build properties in Visual Studio. Select the Configuration Properties > Linker > General property page. Modify the Version property.

What is .NET versioning?

Versioning is the creation and management of multiple product releases, all of which have the same general function, but are improved, upgraded or customized. While many developers and vendors use the term in different contexts, versioning most often applies to operating systems, software artifacts and web services.


1 Answers

if you call dotnet build /p:Version=YourVersionNumberHere, the build will also set the assembly version. So in your build scripts you can easily read the current build number and set it as the patch.

For example in appveyor the build number is exposed as a variable called APPVEYOR_BUILD_NUMBER, so if you were to use powershell you could call dotnet build /p:Version=1.0.$env:APPVEYOR_BUILD_NUMBER

I do something similar with appveyor here, where I set the version number of my nuget package to be the github tag name, and I set the tag name to be a version. So when I want to do a release I just make a github tag of 1.1.0 for example, and it gets published to nuget.

like image 129
TerribleDev Avatar answered Oct 06 '22 13:10

TerribleDev