如何在夜间构建期间自动设置程序集版本?

发布于 2024-09-11 17:22:55 字数 543 浏览 10 评论 0原文

我们有一个夜间构建过程,可以自动对所有 C++ 项目进行版本控制。这是它的工作原理。有一个通用头文件 VersionNumber.h,其中包含特定的 #define 版本号。每晚构建都会检出此文件,增加 #define 后面的整数并将其检入。所有 Visual C++ 项目 #include 都将其标头放入其资源文件中并使用该定义用于指定版本(版本类似于 1.0.3.ThatNumber)。

到目前为止,一切都很好。现在,我希望在同一日常构建中构建相同的 C# 类库。目前,它们都

[assembly: AssemblyVersion("1.0.*")]

在 AssemblyInfo.cs 文件和库中以 1.0.HorribleNumber.AnotherHorribleNumber 作为版本,并且这两个数字与 C++ 项目使用的数字无关。

如何以最少的努力在我的 C# 项目中拥有相同的确定性自动版本编号?

We have a nightly build process that automatically versions all C++ projecs. Here's how it works. There's a common header file VersionNumber.h that has a specific #define for the version number. The nighly build checks this file out, increments the integer behind that #define and checks it in. All Visual C++ projects #include that header into their resource files and use that define for specifying the version (version is smth like 1.0.3.ThatNumber).

So far so good. Now I'd like to have the same for the C# class libraries built in the same daily build. Currently they all have

[assembly: AssemblyVersion("1.0.*")]

in the AssemblyInfo.cs files and libraries end up with 1.0.HorribleNumber.AnotherHorribleNumber as the version and the two numbers don't correlate to the number used by C++ projects.

How do I have the same determenistic automatic version numbering in my C# projects with minimal effort?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

陈甜 2024-09-18 17:22:56

首先,您可以按如下方式指定完整版本:

[assembly: AssemblyVersion("1.0.9.10")]

其次,使此过程更加简单(并与您的 C++ 方法相呼应)的常见方法是拥有一个位于公共位置的 Version.cs 文件(名称不重要),该位置具有其中的版本属性。然后,您可以添加此文件作为所有 cs 项目的链接,请记住从 AssemblyInfo.cs 文件中删除版本属性。通过这种方式,您只需更新一个文件(在运行构建之前)。您还可以将其他常见程序集属性放入 Version.cs 文件中,例如:NeutralResourcesLanguage 或 CLSCompliant。

如果您不使用单一的“Version.cs”方法,那么您可以递归地处理源代码目录结构,并单独更新 AssemblyInfo 文件(在运行构建之前)。

它可能与您无关,但版本号(在 AssemblyVersion 中)的最大范围为 16 位。我发现这成为一个问题,因为这些数字使用了日期。如果您希望有更多自由度,那么 AssemblyFileVersion 就没有这些限制,但在 .Net 中纯粹出于信息目的,而不是程序集标识的一部分。通常将 AssemblyVersion 和 AssemblyFileVersion 设置为相同的值,因为某些工具会显示这些值的组合。

有关 AssemblyVersion 与 AssemblyFileVersion 的更多信息,请参阅以下内容:

AssemblyVersion、 AssemblyFileVersion 和 AssemblyInformationalVersion?

Firstly you can specify the full version as follows:

[assembly: AssemblyVersion("1.0.9.10")]

Secondly, a common approach to make this a little more straightforward (and echoes your C++ approach) is to have a single Version.cs file (name unimportant) that sits in a common location that has the version attributes in it. You can then add this file as a link to all your cs projects, remembering to remove the version attributes from your AssemblyInfo.cs files. In this way you only have a single file to update (before running your build). You can also put other common assembly attributes in your Version.cs file such as: NeutralResourcesLanguage or CLSCompliant.

If you do not use a single "Version.cs" approach, then you can work recursively through your source code directory structure, and update AssemblyInfo files individually (before running your build).

It may not be relevant to you, but the version numbers (in AssemblyVersion) have a maximum range of 16bit. I have seen this become an issue where dates have been used for these numbers. If you wish to have more latitude then AssemblyFileVersion does not have these restriction, but is purely for informational purposes only in .Net, rather than part of the assembly's identity. It is common to set AssemblyVersion and AssemblyFileVersion to the same values as some tools display combinations of these.

See the following for more on AssemblyVersion vs AssemblyFileVersion:

What are differences between AssemblyVersion, AssemblyFileVersion and AssemblyInformationalVersion?

醉生梦死 2024-09-18 17:22:56

我们使用 FinalBuilder 进行自动化构建(我们有 TeamCity 称之为它),它会自动执行此类操作(即它可以从其他地方(ini 文件、环境变量、命令行等)获取构建号,然后更新所有 显然不是唯一的

方法,但是如果您还没有使用过 FinalBuilder 之类的东西,那么请尝试一下 - 我们的经验是您开始想知道为什么您之前花了这么长时间巧妙地使用 Makefiles 和批处理文件...

但如果您不想这样做,您能否获得生成/修改 VersionNumber.h 文件的相同过程,以也吐出 VersionNumber.cs,其中包含 AssemblyVersion 行?然后您可以将该文件包含在您的项目中。

AssemblyVersion 指令不需要与所有其余的 AssemblyInfo 内容位于同一个文件中。

We use FinalBuilder for automated builds (we have TeamCity call it), and it does this sort of stuff automatically (i.e. it can get a build number from somewhere else (ini file, environment variable, command line, whatever) and then update all the assembly versions for you with the build number.)

Obviously not the only way to do it, but if you haven't used something like FinalBuilder, then give it a try - our experience is you start to wonder why you previously spent so long being clever with Makefiles and batch files...

But if you don't want to do that, can you get the same process which generates/modifies the VersionNumber.h file to also spit out VersionNumber.cs, with an AssemblyVersion line in it? Then you can just include that file in your project.

The AssemblyVersion directive doesn't need to be in the same file as all the rest of your AssemblyInfo stuff.

狼性发作 2024-09-18 17:22:56

您可以执行与 C++ 技术相同的操作,但搜索 " assembly: AssemblyVersion( 字符串,并将引号中的数字替换为完整的、所需的版本号。

在 C# 中,通配符版本号告诉编译器自动更新版本号——如果没有通配符,它​​将只使用提供的完整版本号,

例如

[assembly: AssemblyVersion("1.0.3.10")]

将始终使用该版本号,直到您在文件中更改它。

You can do something like you already do for your C++ technique, but search for the "assembly: AssemblyVersion( string and replace the number in quotes with the full, required version number.

In C# the wildcard on the version number tells the compiler to automatically update the version number -- if there's no wildcard, it will just use the full number supplied.

e.g.

[assembly: AssemblyVersion("1.0.3.10")]

Will always use that version number until you change it in the file.

秋千易 2024-09-18 17:22:56

您可以通过添加另一个文件的链接来设置该文件的程序集版本。类似的解决方案是

链接文本

You can set assembly version from another file, by adding a link to it. A similar solution is

link text

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文