📅 February 14, 2022

Versioning Blazor or ASP.NET Core with Continuous Integration

Recently, I wanted to display the version number of my Blazor application on the web. An app version on the web for end-users might not provide much value, however, it provides a quick sanity check for the product team. Below is how I accomplished this.

Set the pipeline name

Setting the pipeline name in a format that can be used for the version makes things simpler. So I set the name (build number) as follows: name: $(Year:yyyy).$(Month).$(DayOfMonth).$(Rev:r). The result of this is something like: 2022.2.14.1.

Configure the Version .NET Core Assemblies task

Azure DevOps has a Version .NET Core Assemblies task available to use in a build pipeline. A sample configuration is below. The example blelow sets the <Version /> property to the build number on the .csproj for Foo.Web.

- task: VersionDotNetCoreAssemblies@2
 displayName: add version number
    Path: 'src/Foo.Web'
    VersionNumber: '$(Build.BuildNumber)'
    Injectversion: True
    FilenamePattern: '.csproj'
    Field: 'Version'
    OutputVersion: 'OutputedVersion'
    AddDefault: true

Display the version in Blazor

There are several ways you could display a version number in a web app. I decided to display the version with a <meta /> tag in <head />. In Blazor Server you would do this in _Host.cshtml.

    <meta name="version" content="@GetType()?.Assembly?.GetName()?.Version?.ToString()" />


After you release the artifact from your build with the changes above, you should be able to view the page source and see the following:

    <meta name="version" content="2022.2.14.1" />

# development | dotnet | devops | blazor