如何使用 .net 解决方案生成的 AssemblyInfo Patcher 更改 TeamCity 中 DLL 的 File/Product 版本?

How to change File/Product version of DLLs in TeamCity using AssemblyInfo Patcher produced from a .net solution?

我的解决方案中有多个 c# class 库(DotNet Core 2.1)项目和用户界面(WPF 项目)。

假设一个 class 库项目属性具有程序集版本 2019.1.15341.0:

此外,将相同的程序集版本分配给用户界面(WPF 应用程序):

[assembly: AssemblyVersion("2019.1.15341.0")]
[assembly: AssemblyFileVersion("2019.1.15341.0")]

在TeamCity中,我配置了AssemblyInfo Patcher:

我使用 TeamCity 构建了完整的解决方案并且构建成功:

现在让我们看看构建完整解决方案后生成的 属性 工件:

1.项目 1(Class 库,DLL 属性):

2。用户界面(WPF 项目):

我看到 TeamCity 根据 build counterbuild vcs number 更改了 UserInterface.exe's Version,但为什么 DLL's version 没有更改?我缺少任何步骤吗?或者其他什么?

Any information I am missing please inform.

EXE 的属性似乎符合预期。主要问题在于 DLL:属性 未更改。

根据 TeamCity AssemblyInfo patcher docs:

...after this build feature is configured, it will run before the first build step. TeamCity will first perform replacement in the files found in the build checkout directory and then run your build.

但是,您在 DLL 项目设置的“包”选项卡上的值(您的第一个屏幕截图)会在构建过程中应用,即 MSBuild 处理您的项目时。我怀疑由 TeamCity Assembly 修补程序设置的值在这里被替换回默认值。

如前所述,它是一个 .Net Core 项目,因此它可能没有 AssemblyInfo.cs 定义程序集属性的地方。

因此转到 TeamCity 中的构建功能,并添加一个构建功能。

  1. Select: 文件内容替换器
  2. (可选)单击加载模板并在 .Net Core
  3. 下搜索或键入版本

  1. 您可以使用自己的正则表达式,例如:<Version>\S*<\/Version> 或使用模板正则表达式:(<(Version)\s*>).*(<\/\s*\s*>)

我使用了替换为:<Version>%MAJOR%.%MINOR%.%build.counter%.%build.vcs.number%</Version>,这样 <version></version> 标签就不会按照我的正则表达式被删除。这完全取决于您的正则表达式,您需要替换什么。

同样,我添加了其他需要的参数:

优点: 构建项目后,我可以在属性中看到预期的结果。

缺点: 多次搜索和替换文件而不是一次(构建功能的数量,执行的次数相同,恢复的次数相同!)