Versioning a .NET Core 2.0 application

When creating our ASP.NET Core 2.0 application, one of the first tasks I had was to create a build for the application. The build will mature and grow over time and acquire additional tasks (such as unit testing steps, deployments to our Azure web hosting etc). But for the time being, I was only creating the most basic of builds for the application to perform Continuous Integration and to deploy to a testing endpoint.

The first problem I encountered was how to version the application using our Team Foundation Services (TFS) build process. Versioning in .NET Core 2.0 does not work the same way as it does in earlier versions of .NET. So I couldn’t just take my previous Powershell script (which I use for versioning my other .NET applications) as it didn’t work.

After reading through lots of documentation and StackOverflow posts, I came across a solution that works and which I have now impemented within the build.

Here’s a link to a utility called dotnet-setversion[^] that will version your .NET Core 2.0 application. After adding the reference to your project, you simply invoke the utility and pass it the version number as a parameter. I achieved this within our build process by adding a new step which invokes a Windows batch file. This batch file invokes the utility which then versions our application.

Within TFS you have the ability to pass arguments to your Windows batch files. I am passing the build version number $(Build.BuildNumber) as the argument.

I then invoke my Windows batch file (called setversion.bat)

Hide Copy Code

@echo off
ECHO Setting version number to %1
cd <projectFolder>
dotnet restore
dotnet setversion %1

This all works perfectly, and the deployed application assemblies are stamped with the correct version number.