The Problem:
In a .NET 6 WPF project, the ProductVersion
obtained from FileVersionInfo
unexpectedly includes a git commit hash, breaking the expected behavior of returning the version set in the project file. The change occurred after updating Visual Studio to receive updates on .NET 8, and the exact cause and solution are unclear.
The Solutions:
Solution 1: Disable inclusion of source revision in informational version
The unexpected inclusion of the git commit hash in the FileVersionInfo.ProductVersion
can be resolved by adding the following line to the project file:
<IncludeSourceRevisionInInformationalVersion>false</IncludeSourceRevisionInInformationalVersion>
This change seems to be introduced by SourceLink related changes in the SDK 8 version. For more information, refer to the GitHub issue: https://github.com/dotnet/sdk/issues/34568
Q&A
Reason behind git commit hash in ProductVersion
?
SDK 8 version changes associated with SourceLink
Solution to remove git commit hash from ProductVersion
IncludeSourceRevisionInInformationalVersion
can be set to false
in the project file