.NET:AssemblyVersionAttribute 中的大修订号

发布于 2024-07-29 08:41:44 字数 392 浏览 5 评论 0 原文

我们约定将构建的版本控制为[主要].[次要].[微].[修订版],例如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 :-)

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

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

发布评论

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

评论(6

记忆で 2024-08-05 08:41:44

更多背景信息:

为什么内部版本号限制为 65535?

由于这不太可能改变,您的选择是:

  • 采用修订模数 65535,这意味着您回到 1
  • 使用版本号中的微字段来拆分版本号将修订版除以 1000 得到版本号。这意味着您的版本可能是 1.0.65.535
  • 不要将 SVN 修订版存储在 AssemblyVersion 中,而是存储在 装配信息版本。 这样,您的应用程序仍然可以出于显示目的访问它,尽管您无法再使用 Windows 资源管理器来快速检查 SVN 修订版
  • 不要将 SVN 修订版存储在 AssemblyVersion 中,而是存储在 AssemblyProduct 或 AssemblyDescription 字段中。 同样,这样您的应用程序仍然可以访问它,而且资源管理器现在也会在属性表中显示它。

A bit more Background information:

Why are build numbers limited to 65535?

As this is unlikely to get changed, your options are:

  • Take the Revision Modulo 65535, which means you are back to 1
  • Use the Micro-Field in your version number to split the version number by dividing the revision by 1000. That means your version could be 1.0.65.535
  • Do not store the SVN Revision in the AssemblyVersion, but instead in the AssemblyInformationalVersion. That way your Application can still access it for display purposes, although you can't use Windows Explorer anymore to quickly check the SVN Revision
  • Do not store the SVN Revision in the AssemblyVersion, but instead in the AssemblyProduct or AssemblyDescription fields. Again, that way your Application can still access it, but also Explorer will now show it in the Property Sheet.
爱冒险 2024-08-05 08:41:44

一种选择可能是仅使用 [AssemblyFileVersion]; 这仍然会引发警告,但至少会构建:

[assembly: AssemblyFileVersion("1.0.0.80000")]

One option might be to just use the [AssemblyFileVersion]; this still raises a warning, but it'll build, at least:

[assembly: AssemblyFileVersion("1.0.0.80000")]
夏有森光若流苏 2024-08-05 08:41:44

我们决定使用相同的约定,并且由于 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.

乖乖哒 2024-08-05 08:41:44

根据 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.

无尽的现实 2024-08-05 08:41:44

此答案适用于使用Azure Build Pipeline、想要插入BuildId值作为程序集版本的最后一个数字并拥有BuildId 值太大的问题。 (> 65535)

我的解决方案是使用 BuildId 的最后 4 或 5 位,这些数字被注入到文件 AssemblyInfo.cs 中.
我不使用模运算,因为版本号看起来与 BuildId 完全不同(达到限制后)。 相反,在我的解决方案中,“短路”版本看起来与 BuildId 类似。

示例

AssemblyVersion1.0.0.0BuildId 为 333。
--> 新的 AssemblyVersion 变为 1.0.0.333。 (数字小,没问题。

AssemblyVersion1.0.0.0BuildId 为 55555。
--> 新的 AssemblyVersion 变为 1.0.0.55555。 (仍在范围内。

AssemblyVersion1.0.0.0BuildId 为 66666。
- -> 新的 AssemblyVersion 变为 1.0.0.6666。 (使用最后 4 位数字。不可能更多。

AssemblyVersion1.0.0.0BuildId是 111111。
--> 新的 AssemblyVersion 变为 1.0.0.11111。 (使用最后 5 位数字。

通过以下步骤轻松使用

第 1 步: 在管道中定义变量 shortBuildId通过这个片段。

variables:
- name: shortBuildId # note: The last 4 or 5 digits of the BuildId, because for the assembly version number the maximum value is 65535
  value: '[not set]' # will be set by powershell script

或者您可以这样定义它。 这取决于您如何定义现有变量的样式。

variables:
  shortBuildId: '[not set]'

第 2 步:将这些任务插入到现有任务之上。

第一个任务创建短 BuildId 并将其保存到变量 shortBuildId 中。

第二个任务更新文件 AssemblyInfo.cs 中的第四个版本字段。 因此,短 buildId 会同时注入到 AssemblyVersionAssemblyFileVersion 中。

注意:在此文件中,您需要一个包含 4 个数字的程序集版本(例如 1.0.0.0)。 如果您只有 3 个数字(例如 1.0.0),它将不起作用。

- task: PowerShell@2
  displayName: Define short build ID
  # If allowed, use the last 5 digits. If they are larger than 65000, use the last 4 digits. Leading zeros are removed.
  # This is needed, because the full build ID can't be used as number for the assembly version.
  inputs:
    targetType: 'inline'
    script: |
      $shortId = $env:BUILD_BUILDID
      $shortId = $shortId % 100000
      if ($shortId -gt 65000) { $shortId = $shortId % 10000 }
      Write-Host "Build ID: $env:BUILD_BUILDID --> $shortId"
      Write-Host "##vso[task.setvariable variable=shortBuildId]$shortId" 
    showWarnings: true

- task: RegexReplace@3
  displayName: Insert shortBuildId into AssemblyInfo:
    InputSearchPattern: 'myProjectDirectory\Properties\AssemblyInfo.cs'
    FindRegex: '(\[assembly: (AssemblyVersion|AssemblyFileVersion)\("\d+\.\d+\.[0-9*]+)\.[0-9*]+("\)\])'
    ReplaceRegex: '$1.$(shortBuildId)$3'
    UseUTF8: true
    UseRAW: true

第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 file AssemblyInfo.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 is 1.0.0.0 and the BuildId is 333.
--> The new AssemblyVersion becomes 1.0.0.333. (Small number, no problem.)

The AssemblyVersion is 1.0.0.0 and the BuildId is 55555.
--> The new AssemblyVersion becomes 1.0.0.55555. (Still in range.)

The AssemblyVersion is 1.0.0.0 and the BuildId is 66666.
--> The new AssemblyVersion becomes 1.0.0.6666. (Uses last 4 digits. More isn't possible.)

The AssemblyVersion is 1.0.0.0 and the BuildId 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.

variables:
- name: shortBuildId # note: The last 4 or 5 digits of the BuildId, because for the assembly version number the maximum value is 65535
  value: '[not set]' # will be set by powershell script

Alternatively you could define it like this. It depends on the style how you did define your already existing variables.

variables:
  shortBuildId: '[not set]'

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, the AssemblyVersion and the AssemblyFileVersion.

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.

- task: PowerShell@2
  displayName: Define short build ID
  # If allowed, use the last 5 digits. If they are larger than 65000, use the last 4 digits. Leading zeros are removed.
  # This is needed, because the full build ID can't be used as number for the assembly version.
  inputs:
    targetType: 'inline'
    script: |
      $shortId = $env:BUILD_BUILDID
      $shortId = $shortId % 100000
      if ($shortId -gt 65000) { $shortId = $shortId % 10000 }
      Write-Host "Build ID: $env:BUILD_BUILDID --> $shortId"
      Write-Host "##vso[task.setvariable variable=shortBuildId]$shortId" 
    showWarnings: true

- task: RegexReplace@3
  displayName: Insert shortBuildId into AssemblyInfo:
    InputSearchPattern: 'myProjectDirectory\Properties\AssemblyInfo.cs'
    FindRegex: '(\[assembly: (AssemblyVersion|AssemblyFileVersion)\("\d+\.\d+\.[0-9*]+)\.[0-9*]+("\)\])'
    ReplaceRegex: '$1.$(shortBuildId)$3'
    UseUTF8: true
    UseRAW: true

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.

失退 2024-08-05 08:41:44

我想通过回答任何使用 semver/gitflow 的人提出以下方案:

AssemblyVersionAttribute SemVer/Gitflow
主要版本 主要
次要版本 次要 补丁
版本号 版本
://nvie.com/posts/a-successful-git-branching-model/ " Gitflow ID

其中“Gitflow ID”是一个数字后跟 0000 - 9999,如下所示:

Gitflow ID 分支
00000 - 09999 版本 (alpha)
10000 - 19999 发布(测试版)
20000 - 29999 发布(RC)
30000 - 65535 开发

00000 - 29999 背后的直觉是这些数字代表某种逻辑负预发布数字,30000< /code> 代表逻辑零,30001 - 65535 代表逻辑正。 更正式地说,这是一种 10 的补码表示,带有 偏移 K = 30000

例如:

  1. 主题分支 feature/A 从 0.0.0.30000 开始
  2. ,同时,主题分支 feature/B 也从 0.0.0.30000 开始
  3. feature/B 合并到 dev >0.0.0.31000 而 feature/A 位于 0.0.0.30021
  4. feature/A 合并来自 dev 的更新 0.0.0.31001
  5. feature/A 合并到 dev 的 code>0.0.0.32000
  6. v1.0-alpha.1 版本从 dev 开始于 1.0.0.00001
  7. v1.0-rc.3 at 1.0.0.20002
  8. 最后v1.0 于 1.0.0.30000 发布到 Master 于
  9. 1.0.1.30000 应用了修补程序 v1.0.1,
  10. 同时 v1.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:

AssemblyVersionAttribute SemVer/Gitflow
Major Version Major
Minor Version Minor
Build Number Patch
Revision Gitflow ID

Where "Gitflow ID" is a digit followed by 0000 - 9999, per the following:

Gitflow ID Branch
00000 - 09999 Release (alpha)
10000 - 19999 Release (beta)
20000 - 29999 Release (RC)
30000 - 65535 Development

The intuition behind 00000 - 29999 is that these numbers represent something of a logical negative pre-release number, 30000 represents logical zero, and 30001 - 65535 represent logical positive. More formally, this is a kind of 10's complement representation, with offset K = 30000.

So for example:

  1. Topic branch feature/A starts at 0.0.0.30000
  2. Simultaneously, topic branch feature/B also starts at 0.0.0.30000
  3. feature/B merges to dev at 0.0.0.31000 while feature/A is at 0.0.0.30021
  4. feature/A merges updates from dev at 0.0.0.31001
  5. feature/A merges to dev at 0.0.0.32000
  6. v1.0-alpha.1 release starts from dev at 1.0.0.00001
  7. v1.0-rc.3 at 1.0.0.20002
  8. Finally v1.0 released to Master at 1.0.0.30000
  9. Hotfix v1.0.1 applied at 1.0.1.30000
  10. Meanwhile v1.1 development continuing at 1.0.1.30002

The above suggests that the development range 30000-65535 could be further subdivided for topic branches, i.e. DDTTT, with DD ranging from 30 to 65 (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. The DDTTT 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 of 30000.

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