从MSBUILD脚本获取次要版本和主要版本 [英] Get minor and major version from MSBUILD script
本文介绍了从MSBUILD脚本获取次要版本和主要版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用Msbuild编译并生成.zip文件和安装程序,我需要assembyInfo的版本号.
I'm using Msbuild to compile and generate .zip files and installers and I need the version number of my assembyInfo.
我正在使用此代码.
<Target Name="getversion">
<GetAssemblyIdentity AssemblyFiles="$(BuildDir)\myprogram.exe">
<Output TaskParameter="Assemblies" ItemName="fooAssemblyInfo"/>
</GetAssemblyIdentity>
<Message Text="Version = %(fooAssemblyInfo.Version)"/>
</Target>
但这返回Version = 2.0.0.29110,我只需要次要和主要版本.
But this returns Version = 2.0.0.29110, I need just the minor and major version.
是否可以在没有自定义任务的情况下读取assembyInfo.cs信息?
Is there any way to read the assembyInfo.cs information without a custom task?
推荐答案
最后,我使用了此代码,不需要其他任务库
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>
这篇关于从MSBUILD脚本获取次要版本和主要版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文