I'm using Msbuild to compile and generate .zip files and installers and I need the version number of my assembyInfo.
I'm using this code.
<Target Name="getversion">
<GetAssemblyIdentity AssemblyFiles="$(BuildDir)\myprogram.exe">
<Output TaskParameter="Assemblies" ItemName="fooAssemblyInfo"/>
</GetAssemblyIdentity>
<Message Text="Version = %(fooAssemblyInfo.Version)"/>
</Target>
But this returns Version = 2.0.0.29110, I need just the minor and major version.
Is there any way to read the assembyInfo.cs information without a custom task?
It can be done using MSBuild Property Functions described here: https://msdn.microsoft.com/en-us/library/dd633440%28v=vs.120%29.aspx
<Target Name="getversion">
<GetAssemblyIdentity AssemblyFiles="$(BuildDir)\myprogram.exe">
<Output TaskParameter="Assemblies" ItemName="fooAssemblyInfo"/>
</GetAssemblyIdentity>
<Message Text="Version = $([System.Version]::Parse(%(fooAssemblyInfo.Version)).ToString(2))" Importance="high" />
</Target>
Output:
Done executing task "GetAssemblyIdentity".
Task "Message"
Task Parameter:Text=Version = 12.0
Task Parameter:Importance=high
Version = 12.0
Done executing task "Message".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With