Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get minor and major version from MSBUILD script

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?

like image 518
Carlos Garces Avatar asked Sep 18 '13 08:09

Carlos Garces


1 Answers

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".
like image 89
Sergei Zinovyev Avatar answered Oct 21 '22 18:10

Sergei Zinovyev