Reputation: 1660
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
?
Upvotes: 0
Views: 2767
Reputation: 2504
The AssemblyName.Version
property must be in the format 0.0.0.0
so that is why your custom Build number cannot be converted to an assembly version by the VersionDotNetCoreAssemblies
task. It cannot convert the dashes and alphanumeric characters into the numeric-only format.
You could change to a build number that fits into 0.0.0.0
Note that 20220126.3.0.0
is not valid as a version number as 20220126 is too large. see this answer. 2022.1.26.3
would be valid. You could use other attributes to store your version as mentioned in the comments.
or take the Build number from the DevOps pipeline and set it where you app can access it. This depends on your hosting. If you are using Docker you can set a variable inside the container or for App service you can set an application setting with the build number.
In DevOps the build number is in an environment variable called "Build_BuildNumber"
Upvotes: 1