Showing long product version in .net 8 application

beginer
beginer
Member
1328 Points
43 Posts

I'm using following code to get production version:

public string GetProductVersion()
{
    var location = Assembly.GetExecutingAssembly().Location;
    if (!string.IsNullOrWhiteSpace(location))
        return FileVersionInfo.GetVersionInfo(location)?.ProductVersion;
    else
        return "0.0.0";
}

Added production version in .csproj file as:

<Project Sdk="Microsoft.NET.Sdk.Web">
  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
    <Version>1.2.0</Version>
    <AssemblyVersion>1.2.0.0</AssemblyVersion>
    <FileVersion>1.2.0.0</FileVersion>
  </PropertyGroup>

But instead of showing version: 1.2.0 it's showing long as:

1.2.0+d2bab83c5786deeba69fab5d188cb5ce530aeaa3

Anyone has any clue on this?

 

Views: 106
Total Answered: 2
Total Marked As Answer: 1
Posted On: 12-Apr-2024 00:20

Share:   fb twitter linkedin
Answers
Rashmi
Rashmi
Member
820 Points
17 Posts
         

It's including Git commit ID included in assembly ProductVersion field when building with sdk 8, see here: https://github.com/dotnet/sdk/issues/34568

Add following property in the csproj file:

IncludeSourceRevisionInInformationalVersion 

as:

<Project Sdk="Microsoft.NET.Sdk.Web">
  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
    <Version>1.2.0</Version>
    <AssemblyVersion>1.2.0.0</AssemblyVersion>
    <FileVersion>1.2.0.0</FileVersion>
    <IncludeSourceRevisionInInformationalVersion>false</IncludeSourceRevisionInInformationalVersion>
  </PropertyGroup>
Posted On: 12-Apr-2024 00:43
beginer
beginer
Member
1328 Points
43 Posts
         

Thanks. it worked.

Posted On: 14-Apr-2024 22:23
 Log In to Chat