How can one read the AssemblyFileVersion, or its components AssemblyFileMajorVersion, AssemblyFileMinorVersion, AssemblyFileBuildNumber, AssemblyFileRevision, within the .csproj, following compilation?
I have tried the following which pulls the information from the built assembly:
<Target Name="AfterCompile">
<GetAssemblyIdentity AssemblyFiles="$(TargetPath)">
<Output
TaskParameter="Assemblies"
ItemName="MyAssemblyIdentities"/>
</GetAssemblyIdentity>
<Message Text="AssemblyVersion = %(MyAssemblyIdentities.Version)" />
</Target>
But that retrieves the AssemblyVersion and not the AssemblyFileVersion. There does not seem to be a documented metadata entry for the latter. I also tried:
<Import Project="$(MSBuildExtensionsPath)\ExtensionPack\MSBuild.ExtensionPack.tasks" />
<Target Name="AfterCompile">
<MSBuild.ExtensionPack.Framework.Assembly TaskAction="GetInfo" NetAssembly="$(TargetPath)">
<Output TaskParameter="OutputItems" ItemName="Info" />
</MSBuild.ExtensionPack.Framework.Assembly>
<Message Text="AssemblyFileVersion = %(Info.FileVersion)" />
</Target>
Unfortunately, while this retrieves the correct value, it also file locks the assembly until VS2008 is closed.
Frankly, neither is what I want as I would rather read the information from the AssemblyInfo.cs directly. However, I cannot figure out how to do that. I assumed AssemblyInfo in the MSBuild Extensions was one way, but it seems focused on writing to the AssemblyInfo and not retrieving values from it.
How can I best accomplish this?