如何使用 AssemblyInfoTask 更改程序集版本号?
我正在尝试自动化为所有 DLL 设置版本的过程,在花了一些时间后我开始了解最有可能实现它的 AssemblyInfo
任务。
所以我继续安装它,特别是版本1.0.51130.0。
安装后,我在 .cspoj
文件中手动添加了 AssemblyInfoTask
的 Import
标签(通过卸载每个项目)(解决方案有超过 35 个)项目文件)。
<Import Project="$(MSBuildExtensionsPath)\Microsoft\AssemblyInfoTask\Microsoft.VersionNumber.Targets"/>
接下来,我修改了 Microsoft.VersionNUmber.Target
文件,该文件将安装在路径:C:\Program Files\MSBuild\Microsoft\AssemblyInfoTask
中,并修改了以下部分:
<!-- Properties for controlling the Assembly Version -->
<PropertyGroup>
<AssemblyMajorVersion>4</AssemblyMajorVersion>
<AssemblyMinorVersion>0</AssemblyMinorVersion>
<AssemblyBuildNumber></AssemblyBuildNumber>
<AssemblyRevision></AssemblyRevision>
<AssemblyBuildNumberType>DateString</AssemblyBuildNumberType>
<AssemblyBuildNumberFormat>01MMdd</AssemblyBuildNumberFormat>
<AssemblyRevisionType>AutoIncrement</AssemblyRevisionType>
<AssemblyRevisionFormat>00</AssemblyRevisionFormat>
</PropertyGroup>
<!-- Properties for controlling the Assembly File Version -->
<PropertyGroup>
<AssemblyFileMajorVersion>4</AssemblyFileMajorVersion>
<AssemblyFileMinorVersion>0</AssemblyFileMinorVersion>
<AssemblyFileBuildNumber></AssemblyFileBuildNumber>
<AssemblyFileRevision></AssemblyFileRevision>
<AssemblyFileBuildNumberType>DateString</AssemblyFileBuildNumberType>
<AssemblyFileBuildNumberFormat>01MMdd</AssemblyFileBuildNumberFormat>
<AssemblyFileRevisionType>AutoIncrement</AssemblyFileRevisionType>
<AssemblyFileRevisionFormat>00</AssemblyFileRevisionFormat>
</PropertyGroup>
接下来,我在每个项目中将 assembleInfo.cs
文件的版本设置为 1.0.0.0
。最后我保存并关闭它,重新打开解决方案并构建。它就像冠军一样工作!
现在想要的是将版本自定义为 4.0.1053.1
,其中 10
是年份指示符,即 2010 年,53
表示周数,最后 1
表示修订号。
如何使用 AssemblyInfo
任务来实现此目的?我看到几篇文章称,Build Extension Pack 中提供了新版本的 AssemblyInfo
Task。
我已安装 MSBuild Extension Pack 2010 年 12 月,其版本为 MSBuild Extension Pack 4.0.2.0 Installer
I am trying to automate the process for setting the Version for all DLL's, after spending some time I came to know the AssemblyInfo
Task with which it can most likely be achieved.
So I went ahead and installed it, specifically version 1.0.51130.0.
After Installing, I manually added the Import
Tag (by unloading the each project) of AssemblyInfoTask
in .cspoj
files (the solution has more than 35 proj files).
<Import Project="$(MSBuildExtensionsPath)\Microsoft\AssemblyInfoTask\Microsoft.VersionNumber.Targets"/>
Next I modified the Microsoft.VersionNUmber.Target
file which will be installed in path: C:\Program Files\MSBuild\Microsoft\AssemblyInfoTask
, and I modified the following section:
<!-- Properties for controlling the Assembly Version -->
<PropertyGroup>
<AssemblyMajorVersion>4</AssemblyMajorVersion>
<AssemblyMinorVersion>0</AssemblyMinorVersion>
<AssemblyBuildNumber></AssemblyBuildNumber>
<AssemblyRevision></AssemblyRevision>
<AssemblyBuildNumberType>DateString</AssemblyBuildNumberType>
<AssemblyBuildNumberFormat>01MMdd</AssemblyBuildNumberFormat>
<AssemblyRevisionType>AutoIncrement</AssemblyRevisionType>
<AssemblyRevisionFormat>00</AssemblyRevisionFormat>
</PropertyGroup>
<!-- Properties for controlling the Assembly File Version -->
<PropertyGroup>
<AssemblyFileMajorVersion>4</AssemblyFileMajorVersion>
<AssemblyFileMinorVersion>0</AssemblyFileMinorVersion>
<AssemblyFileBuildNumber></AssemblyFileBuildNumber>
<AssemblyFileRevision></AssemblyFileRevision>
<AssemblyFileBuildNumberType>DateString</AssemblyFileBuildNumberType>
<AssemblyFileBuildNumberFormat>01MMdd</AssemblyFileBuildNumberFormat>
<AssemblyFileRevisionType>AutoIncrement</AssemblyFileRevisionType>
<AssemblyFileRevisionFormat>00</AssemblyFileRevisionFormat>
</PropertyGroup>
Next I set the assemblyInfo.cs
file's version to 1.0.0.0
in every project. Finally I saved and close it, reopened solution, and built. It works like a champ!
Now what want is to customize the Version to 4.0.1053.1
where 10
is the part of year indicator which is 2010 and 53
denotes the week number, at last 1
denotes revision number.
How to achieve this using the AssemblyInfo
Task? I came across several posts that a new version of AssemblyInfo
Task is available in Build Extension Pack.
I have installed the MSBuild Extension Pack December 2010 and its version is MSBuild Extension Pack 4.0.2.0 Installer
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我在 Jenkins 中通过使用 List Subversion Tags 参数类型进行参数化的包构建来执行此操作。 Subversion 标签必须遵循版本号格式(major.minor.revision.build),例如
tags/2.0.0.1
。然后将标签名称分配给 Jenkins 参数,例如$VERSION
变为2.0.0.1
我使用
WriteLinesToFile
msbuild 任务写出程序集属性到 PropertyInfo.cs 旁边的第二个文件(称为 VersionInfo.cs)。当签入源代码管理时,这仅包含默认版本号:构建服务器上的包构建通过 AsmVersion 参数传入版本:
.csproj 文件被修改为具有
BeforeBuild
目标 ( Visual Studio 会为您创建一个已注释掉的版本):在 Visual Studio 中构建时,或者不传入 AsmVersion,您的程序集将具有默认版本 0.0.0.0。在包构建中构建时,您将获得所需的构建号。
I do this in Jenkins by having a package build that is parameterised using the List Subversion Tags parameter type. The Subversion tag must follow the version number format (major.minor.revision.build), e.g.
tags/2.0.0.1
. The tag name is then assigned to a Jenkins parameter, e.g.$VERSION
becomes2.0.0.1
I use the
WriteLinesToFile
msbuild task to write out the assembly attribute to a second file alongside the PropertyInfo.cs called VersionInfo.cs. As checked in to source control, this just contains a default version number:The package build on the build server passes in the version via the AsmVersion parameter:
The .csproj file is modified to have a
BeforeBuild
target (Visual Studio creates a commented out one for you):When building in Visual Studio, or without passing in the AsmVersion, your assembly will have a default version of 0.0.0.0. When building in the package build, you will get your desired build number.
首先..使用从每个项目链接的globalassembleinfo.cs。
将其作为链接文件添加到每个项目中。
这意味着您更新一个文件,而不是 30 多个 assemblyinfo 文件...然后:
使用 MSBuild.Community.Tasks ....
然后打电话
假设你有类似的事情:
First.. use a globalassemblyinfo.cs that is linked from each project.
Add its as linked file to each project.
This means you update one file, not 30+ assemblyinfo files...then:
use MSBuild.Community.Tasks....
Then call
Assuming you have something like:
正如 @bruceboughton 提议的,您可以在编译期间轻松生成版本程序集文件,而无需使用
MSBuild.Community.Tasks
库:从
Properties\AssemblyInfo.cs
文件中删除您在生成的文件中指定的参数的定义。之后,您可以通过向 msbuild 添加参数来指定版本:
As @bruceboughton proposed, you can easily generate a version assembly file during compilation without using
MSBuild.Community.Tasks
library:Remove definitions of the parameters you specify in the generated file from
Properties\AssemblyInfo.cs
file.After that you can specify version by adding a parameter to the msbuild:
.NET Core 样式 .csproj 文件的更新:如果您在转换为 .NET Core 使用的新 .csproj 格式后遇到此问题,您可以 只需设置 Version 属性(无需担心 MSBuild 任务)。
Update for .NET Core style .csproj files: If you've come upon this question after having transitioned to the new .csproj format used by .NET Core, you can just set the Version property (no need to to bother with MSBuild tasks).
我最终如何让它在 MSBuild 版本 12(VS 2013)上工作。
它与 XML 不兼容,因此必须更改至:
部分并添加以下内容:How I finally got this to work MSBuild version 12 (VS 2013).
which is not XML compatible, so has to be changed to:
<Target Name="BeforeBuild">
section and added the following: