Search code examples
c#.net.net-assemblywinui-3

Strange information when getting app version information


i have a winui 3 app and i am using this code for getting app version info:

assembly = Assembly.GetEntryAssembly();
assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion

Previously, I had Windows 11 - 22H2 and Visual Studio 2022 v17.7 + net7.0 And the output of the above code was as follows:

4.0.0

Today I changed Windows (Clean Install) to 23H2 and Visual Studio 2022 v17.8 /Visual Studio 2022 v18.0-Preview1 + net8.0 but when i run my app (from visual studio) The output of the above code is almost as follows:

4.0.0 + ea32asd354ad5a4d5a4sda5a54da54da4das54da4d

i changed .net version to net7.0 or i moved to previous versions (from git) and output is strange. but when i run my app from ms store output is correct, or when i create a new project output is correct but i dont know why my project is curropted


Solution

  • It is not a bug, it is a breaking change. As discussed in the Developer Community a new behavior has been included in .NET SDK: Source Link included in the .NET SDK.

    To get the previous behavior and avoid that the commit id be shown in the AssemblyInformationalVersion include the following setting in your .csproj file:

    <IncludeSourceRevisionInInformationalVersion>false</IncludeSourceRevisionInInformationalVersion>
    

    If there are multiple projects in the solution I would recommend to add the setting in the "Directory.Build.props" file instead of adding the setting in each project file. "Directory.Build.props" file must be in the root folder that contains your source and must be similar to this:

    <Project>
      <PropertyGroup>
          <IncludeSourceRevisionInInformationalVersion>false</IncludeSourceRevisionInInformationalVersion>
      </PropertyGroup>
    </Project>