Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
459 views
in Technique[技术] by (71.8m points)

.net - 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Finally I have used this code that not require additional task libraries

<Target Name="getversion">
    <GetAssemblyIdentity AssemblyFiles="$(BuildDir)myfile.exe">
        <Output TaskParameter="Assemblies" ItemName="myAssemblyInfo"/>
    </GetAssemblyIdentity>
    <PropertyGroup>
        <Pattern>(d+).(d+)</Pattern>
        <In>%(myAssemblyInfo.Version)</In>
        <OutVersion>$([System.Text.RegularExpressions.Regex]::Match($(In), $(Pattern)))</OutVersion>
    </PropertyGroup>
</Target>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...