Search code examples
c#.net.net-6.0.net-8.0

FileVersionInfo.ProductVersion suddenly contains git commit hash


I have a .NET 6 WPF project and cannot figure out what changed as the ProductVersion of my assembly suddenly contains a git commit hash.

My project file always looked like this, where I also updated the version information:

  <PropertyGroup>
    <OutputType>WinExe</OutputType>
    <TargetFramework>net6.0-windows</TargetFramework>
    <UseWPF>true</UseWPF>
    ...
    <Version>0.9.2</Version>
  </PropertyGroup>

Then, in my code I use the following to get the version as string:

 string? productVersion = FileVersionInfo.GetVersionInfo(Assembly.GetEntryAssembly()!.Location).ProductVersion;

This always returned the version as expected, e.g. 0.9.2, exactly as it was set in the project file. But something changed and now it looks like this: 0.9.2+abf5b643b64475a8b1d7d89284e3478b1ba4a431. This is also what shows up in Explorer on the Details tabs of the .dll and .exe files.

I do regularly update Visual Studio in order to receive updates on .NET 8 which I use in other projects, so it may be related to some update. But I've no idea what exactly changed or how I can define the ProductVersion to not include the git commit hash (and yes, it's the commit hash). Haven't worked on the WPF project for a while as well, so don't know when this behavior changed.

Ironically, I needed the git commit in the past so had to put in some extra effort to have this available, though abbreviated to 8 characters.

Any ideas?


Solution

  • The described behavior can be disabled by adding

    <IncludeSourceRevisionInInformationalVersion>false</IncludeSourceRevisionInInformationalVersion>
    

    to the project file.

    It seems to be introduced by SourceLink related changes in the SDK 8 version. I found an existing github issue as well: https://github.com/dotnet/sdk/issues/34568