Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
477 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 Reply

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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...