Something, possibly MSBuild, is appending a long string of numbers and characters to the Product version in my assembly's property sheet:
2024.6.22.6+9f3a8da557d9ed6941ee2dd3751916eb3ff1cece
It should be just this:
2024.6.22.6
Here's my project file:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
...
(other stuff)
...
<FileVersion>2024.6.22.6</FileVersion>
<Version>2024.6.22.6</Version>
</PropertyGroup>
</Project>
The official documentation doesn't appear to address this issue. I tried the <VersionSuffix />
element, as well as <InformationalVersion />
, <AssemblyVersion />
and <ProductVersion />
, but none of those made a difference.
How can I fix this and get rid of the extra characters?
--EDIT--
The problem originates with the auto-generated AssemblyInfo.vb
file:
Assembly: System.Reflection.AssemblyInformationalVersionAttribute("2024.6.22.6+8ae973ace79d1088bac4753cdea9c07b78f68709")
MSBuild is taking the value set there over what is specified in the project file.
I've been able to mitigate this by using my build script to insert a custom target that removes the offending line of code:
<Target Name="RemoveAssemblyInfoMetadata" BeforeTargets="CoreCompile">
<PropertyGroup>
<AssemblyInfoFilePattern>.*AssemblyInfo\.vb</AssemblyInfoFilePattern>
</PropertyGroup>
<Exec Command="powershell -Command "
$Files = Get-ChildItem -Path $(IntermediateOutputPath) -Filter '*.vb' -File -Recurse | Where-Object { $_.Name -match $env:AssemblyInfoFilePattern };
foreach ($File in $Files) {
$Content = Get-Content $File.FullName;
$FilteredContent = $Content | Where-Object { $_ -notmatch 'AssemblyInformationalVersionAttribute' };
$FilteredContent | Set-Content $File.FullName;
}
"" />
</Target>
(Note: this assumes inclusion of the <InformationalVersion />
element in the project file.)
It works, but it sure seems like a kludge. Probably because it is.
If anyone knows of a more elegant way to instruct MSBuild to override the value set in the auto-generated AssemblyInfo.vb
file, I'm all ears.
You will want to disable adding the source control information (git commit id) to the informational version by setting the following property in your vbproj/csproj file:
<PropertyGroup>
<IncludeSourceRevisionInInformationalVersion>False</IncludeSourceRevisionInInformationalVersion>
</PropertyGroup>