我们约定将构建的版本控制为[主要].[次要].[微].[修订版],例如2.1.2.33546。
我们的构建脚本会自动更新包含的 AssemblyInfo.cs 文件,
[assembly: AssemblyVersion("x.y.z.w")]
以便将版本号嵌入到程序集中。
但我们的 Subversion 存储库刚刚达到修订版 #65535,这破坏了我们的构建。
事实证明,版本号中的每个数字的最大值均为 65534(可能是由于 Windows 限制)。
你遇到过这个问题吗? 有什么好的解决方案/解决方法吗?
我们喜欢嵌入修订号的方案,而且我们显然不能只重置 Subversion 服务器:-)
We have the convention of versioning our builds as [major].[minor].[micro].[revision], e.g. 2.1.2.33546.
Our build-script automatically updates an AssemblyInfo.cs file containing
[assembly: AssemblyVersion("x.y.z.w")]
in order to embed the version-number in the assembly.
But our Subversion-repository just reached revision #65535, which broke our build.
It turns out that each number in the version-number has a maximum value of 65534 (probably due to a Windows-restriction).
Have you encountered this problem? Any good solutions/workarounds?
We like the scheme of embedding the revision-number and we obviously can't just reset our Subversion-server :-)
发布评论
评论(6)
更多背景信息:
为什么内部版本号限制为 65535?
由于这不太可能改变,您的选择是:
A bit more Background information:
Why are build numbers limited to 65535?
As this is unlikely to get changed, your options are:
一种选择可能是仅使用
[AssemblyFileVersion]
; 这仍然会引发警告,但至少会构建:One option might be to just use the
[AssemblyFileVersion]
; this still raises a warning, but it'll build, at least:我们决定使用相同的约定,并且由于 Windows 版本号的限制,我们选择删除版本号的“微”部分以保留修订号。 我们的版本号现在为
[major].[minor].[revision / 10000].[revision % 10000]
,因此从修订版 65535 构建的程序集的版本为 2.01.6.5535。We decided to use the same convention, and due to the limitations of Windows version numbers we chose to drop the "micro" part of our version numbers in order to preserve the revision number. Our version numbers are now
[major].[minor].[revision / 10000].[revision % 10000]
, so the assemblies built from revision 65535 have the version 2.01.6.5535.根据 MSDN,AssemblyVersionAttribute 的组件版本号限制为
UInt16。 MaxValue - 1
由程序集元数据决定,即您无法在程序集文件中存储更大的数字。 正如 Marc Gravell 所建议的,文件版本可能对您来说就足够了,具体取决于谁将读取您的版本号。According to MSDN, the components of the AssemblyVersionAttribute version number are limited to
UInt16.MaxValue - 1
by the assembly meta data, i.e. you can't store larger numbers in an assembly file. The file version, as Marc Gravell suggests, might be enough for you, depending on who will read your version number.此答案适用于使用Azure Build Pipeline、想要插入BuildId值作为程序集版本的最后一个数字并拥有
BuildId
值太大的问题。 (> 65535)我的解决方案是使用
BuildId
的最后 4 或 5 位,这些数字被注入到文件AssemblyInfo.cs
中.我不使用模运算,因为版本号看起来与 BuildId 完全不同(达到限制后)。 相反,在我的解决方案中,“短路”版本看起来与 BuildId 类似。
示例:
AssemblyVersion
为1.0.0.0
,BuildId
为 333。--> 新的 AssemblyVersion 变为
1.0.0.333
。 (数字小,没问题。)AssemblyVersion
为1.0.0.0
,BuildId
为 55555。--> 新的 AssemblyVersion 变为
1.0.0.55555
。 (仍在范围内。)AssemblyVersion
为1.0.0.0
,BuildId
为 66666。- -> 新的 AssemblyVersion 变为
1.0.0.6666
。 (使用最后 4 位数字。不可能更多。)AssemblyVersion
为1.0.0.0
,BuildId
是 111111。--> 新的 AssemblyVersion 变为
1.0.0.11111
。 (使用最后 5 位数字。)通过以下步骤轻松使用
第 1 步: 在管道中定义变量
shortBuildId
通过这个片段。或者您可以这样定义它。 这取决于您如何定义现有变量的样式。
第 2 步:将这些任务插入到现有任务之上。
第一个任务创建短 BuildId 并将其保存到变量
shortBuildId
中。第二个任务更新文件
AssemblyInfo.cs
中的第四个版本字段。 因此,短 buildId 会同时注入到AssemblyVersion
和AssemblyFileVersion
中。注意:在此文件中,您需要一个包含 4 个数字的程序集版本(例如
1.0.0.0
)。 如果您只有 3 个数字(例如1.0.0
),它将不起作用。第3步:调整与您的项目相关的第二个任务中的路径。
编辑
InputSearchPattern
的值。如果您想将 ShortBuildId 插入解决方案的所有项目中,只需编写
InputSearchPattern: '**\AssemblyInfo.cs'
Credit
感谢Edmund Weitz 博士感谢他的伟大工具 The Regex Coach,该工具可以免费使用。
This answer is for people, who use the Azure Build Pipeline, want to insert the BuildId value as last number of the assembly version and have a problem with a too large value of the
BuildId
. (> 65535)My solution is to use the last 4 or 5 digits of the
BuildId
, which are injected into the fileAssemblyInfo.cs
.I don't use the modulo operation, because than the version number would look totally different from the BuildId (after reaching the limit). Instead in my solution the "shorted" version looks similar to the BuildId.
Examples:
The
AssemblyVersion
is1.0.0.0
and theBuildId
is 333.--> The new AssemblyVersion becomes
1.0.0.333
. (Small number, no problem.)The
AssemblyVersion
is1.0.0.0
and theBuildId
is 55555.--> The new AssemblyVersion becomes
1.0.0.55555
. (Still in range.)The
AssemblyVersion
is1.0.0.0
and theBuildId
is 66666.--> The new AssemblyVersion becomes
1.0.0.6666
. (Uses last 4 digits. More isn't possible.)The
AssemblyVersion
is1.0.0.0
and theBuildId
is 111111.--> The new AssemblyVersion becomes
1.0.0.11111
. (Uses last 5 digits.)Easy usage by following steps
Step 1: Define the variable
shortBuildId
in your pipeline by this snippet.Alternatively you could define it like this. It depends on the style how you did define your already existing variables.
Step 2: Insert these tasks above the existing tasks.
The first task creates the short BuildId and saves it to variable
shortBuildId
.The second task updates the 4th version field in the file
AssemblyInfo.cs
. So the short buildId is injected into both, theAssemblyVersion
and theAssemblyFileVersion
.Note: In this file you need an assembly version with 4 numbers (e.g.
1.0.0.0
). If you have only 3 numbers (e.g.1.0.0
) it will not work.Step 3: Adjust the path in the second task related to your project.
Edit the value of
InputSearchPattern
.If you want to insert the shortBuildId into all projects of your solution, just write
InputSearchPattern: '**\AssemblyInfo.cs'
Credit
Thanks to Dr. Edmund Weitz for his great tool The Regex Coach, which is free to use.
我想通过回答任何使用 semver/gitflow 的人提出以下方案:
其中“Gitflow ID”是一个数字后跟
0000
-9999
,如下所示:00000
-09999
10000
-19999
20000
-29999
30000
-65535
00000
-29999
背后的直觉是这些数字代表某种逻辑负预发布数字,30000< /code> 代表逻辑零,
30001
-65535
代表逻辑正。 更正式地说,这是一种 10 的补码表示,带有 偏移K = 30000
。例如:
0.0.0.30000
开始0.0.0.30000
开始>0.0.0.31000
而 feature/A 位于0.0.0.30021
0.0.0.31001
code>0.0.0.32000
1.0.0.00001
1.0.0.20002
1.0.0.30000
发布到 Master 于1.0.1.30000
应用了修补程序 v1.0.1,1.0.1.30002
继续进行由上可知,开发范围
30000-65535
可以进一步细分为主题分支,即DDTTT
,其中DD
范围为30
到65
(发布前最多 65 - 30 + 1 = 36 个开发 PR)。 或者,整个范围可以无区别地用于开发和主题分支; 在这种情况下,从 dev 合并到 topic 将使 topic 为 dev + 1,反之亦然。 无论哪种情况都允许在主题分支级别有多个相同的版本号,但任何开发提交只有一个版本号。DDTTT
安排使得哪个版本号代表开发提交(例如57000
)更加清晰,但代价是限制版本中开发提交的数量。 然而,假设发布频率足够频繁,这应该不是问题。 无论如何,生产版本显然具有30000
的 gitflow ID。I'd like to propose by way of answer the following scheme for anyone using semver/gitflow:
Where "Gitflow ID" is a digit followed by
0000
-9999
, per the following:00000
-09999
10000
-19999
20000
-29999
30000
-65535
The intuition behind
00000
-29999
is that these numbers represent something of a logical negative pre-release number,30000
represents logical zero, and30001
-65535
represent logical positive. More formally, this is a kind of 10's complement representation, with offsetK = 30000
.So for example:
0.0.0.30000
0.0.0.30000
0.0.0.31000
while feature/A is at0.0.0.30021
0.0.0.31001
0.0.0.32000
1.0.0.00001
1.0.0.20002
1.0.0.30000
1.0.1.30000
1.0.1.30002
The above suggests that the development range
30000-65535
could be further subdivided for topic branches, i.e.DDTTT
, withDD
ranging from30
to65
(max 65 - 30 + 1 = 36 dev PRs until release). Alternatively, the whole range could be used for development and topic branches without distinction; in this case, merging from dev to topic would have topic be dev + 1 and vice-versa. Either case allows there to be multiple identical version numbers at the topic branch level, but only a single version number for any dev commit. TheDDTTT
arrangement makes it clearer which version number represents a dev commit (e.g.57000
) at the expense of limiting the number of dev commits in a release. However, assuming a frequent enough release cadence, this should not be a problem. At any rate, production releases are clearly seen as having gitflow IDs of30000
.