从 MSBUILD 脚本获取次要版本和主要版本

Get minor and major version from MSBUILD script(从 MSBUILD 脚本获取次要版本和主要版本)
本文介绍了从 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 脚本获取次要版本和主要版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Multicast delegate weird behavior in C#?(C# 中的多播委托奇怪行为?)
How to store delegates in a List(如何将代表存储在列表中)
Delegate.CreateDelegate() and generics: Error binding to target method(Delegate.CreateDelegate() 和泛型:错误绑定到目标方法)
CreateDelegate with unknown types(具有未知类型的 CreateDelegate)
Does Funclt;Tgt;.BeginInvoke use the ThreadPool?(Funclt;Tgt;.BeginInvoke 使用线程池吗?)
How to create a delegate to an instance method with a null target?(如何为具有空目标的实例方法创建委托?)