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>
但这返回版本 = 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 脚本获取次要版本和主要版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:从 MSBUILD 脚本获取次要版本和主要版本
基础教程推荐
- Moq It.Is<>不匹配 2022-01-01
- 当值可以是对象或空数组时反序列化 JSON 2022-01-01
- 禁止输入少量字符,例如'<'、'&a 2022-01-01
- 如何使用 .Net 检查 Active Directory 服务器是否已启动并正在运行? 2022-01-01
- 如果有人提交恶意软件Nuget包怎么办? 2022-01-01
- .NET SerialPort DataReceived 事件未触发 2022-01-01
- C# 从 List<List<int>> 中删除重 2022-01-01
- WPF 模态进度窗口 2022-01-01
- 我应该在后面的代码中直接使用 Linq To SQL 还是使 2022-01-01
- Azure Functions:CosmosDBTrigger 未在 Visual Studio 中触发 2022-01-01
