'Displaying the version in an ASP.NET Core / Blazor project set from Azure DevOps

I want to display a version on my Blazor app that I set in my Azure DevOps pipeline. I'm using the VersionDotNetCoreAssemblies task in DevOps:

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

which logs the following:

Source Directory:  src/Claims.Web
Filename Pattern: .csproj
Version Number/Build Number: 2022-01-25.10-Claims
Version Filter to extract build number: \d+\.\d+\.\d+\.\d+
Field to update (all if empty): Version
Add default field (all if empty): true
Output: Version Number Parameter Name: OutputedVersion
Inject Version: true
SDK names: Microsoft.NET.Sdk
Using provided version number directly
Extracted Version: 2022-01-25.10-Claims
Matched the file 'Claims.Web.csproj' using the SDK name 'Microsoft.NET.Sdk'
Adding file Claims.Web.csproj as is a .NETCore Project
Will apply 2022-01-25.10-Claims to 1 files.
Getting just the PropertyGroup that contains the single version fields
Found <PropertyGroup> [1] blocks
The <Version> version is not present in the file so adding it
The src\Claims.Web\Claims.Web.csproj file only targets 1 framework
src\Claims.Web\Claims.Web.csproj - version applied
Set the output variable 'OutputedVersion' with the value 2022-01-25.10-Claims
(node:1484) Warning: Use Cipheriv for counter mode of aes-256-ctr

2022-01-25.10-Claims is the version I want to display on the web. So, at the moment I'm using the following on my page:

@GetType()?.Assembly?.GetName()?.Version?.ToString()

However, that displays 2022.0.0.0

Currently, my csproj does not contain a <Version /> property, but I don't believe that is required from what I can tell. My understanding is the VersionDotNetCoreAssemblies task should add it if necessary.

If relevant, after my VersionDotNetCoreAssemblies task, I run a dotnet restore and a dotnet publish.

What do I need to modify to display the Version Number/Build Number of 2022-01-25.10-Claims?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source