从 MSBUILD 脚本获取次要版本和主要版本 [英] Get minor and major version from MSBUILD script

查看:26
本文介绍了从 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>

但这返回版本 = 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆