简体   繁体   English

如何在我的许多 C# 项目的树中协调程序集版本信息?

[英]How do I coordinate assembly version information in my tree of many C# projects?

What approaches have you taken to coordinating changes to version and Copyright for groups of assemblies?您采取了哪些方法来协调对程序集组的版本和版权的更改?

I have a tree of many csprojs each with its own AssemblyInfo file.我有一棵由许多 csprojs 组成的树,每个都有自己的 AssemblyInfo 文件。 As part of my build process I want to set copyright year and version.作为构建过程的一部分,我想设置版权年份和版本。 It looks like the following options be be available but file modification is the only one I've seen thus far:看起来以下选项可用,但文件修改是我迄今为止看到的唯一一个:

  • Modify all files via script通过脚本修改所有文件
  • Include resource with date (a macro, a singleton class with public static variables)包括带有日期的资源(一个宏,一个 singleton class 和公共 static 变量)
  • Override AssemblyVersion on command line ( -DAssemblyVersion="1.0.0.1"?)在命令行上覆盖 AssemblyVersion (-DAssemblyVersion="1.0.0.1"?)
  • Reference Environment variable ( [assembly: AssemblyFileVersion("${ENV.VERSION")] )参考环境变量( [assembly: AssemblyFileVersion("${ENV.VERSION")]

I'm used to keeping the source tree clean of generated files in Java/C++ via command line params, defines and centralizing all version specification in a single file.我习惯于通过命令行参数保持 Java/C++ 中生成的文件的源代码树干净,在单个文件中定义和集中所有版本规范。

What approach to do you use to keep the versions in sync and manageable?您使用什么方法来保持版本同步和可管理?

Thanks谢谢

Peter彼得

In the top folder, I place a CommonAssemblyInfo.cs that contains the... common stuff, such as copyright and FileVersion.在顶部文件夹中,我放置了一个 CommonAssemblyInfo.cs,其中包含...常见的东西,例如版权和 FileVersion。 This file is just contains some default attributes and is regenerated by a script(a simple.bat file) on the build server, Hudson in my case.该文件仅包含一些默认属性,并由构建服务器上的脚本(一个 simple.bat 文件)重新生成,在我的例子中是 Hudson。 Remove these common attributes in each of the projects AssemblyInfo.cs.在每个项目 AssemblyInfo.cs 中删除这些公共属性。

In each project in the solution, I add this file.在解决方案的每个项目中,我都添加了这个文件。 but use "Add as link" - available in the drop down of the "Add" button when you add an existing file.但使用“添加为链接” - 添加现有文件时,在“添加”按钮的下拉菜单中可用。 ie all projects just contains a reference to the same file, so there's only one file to update.即所有项目只包含对同一文件的引用,因此只有一个文件需要更新。

Regardless of which route you take to actually update the version number, you can use an individual AssemblyInfo.cs file to specify a shared version.无论您采用哪种方式来实际更新版本号,都可以使用单独的 AssemblyInfo.cs 文件来指定共享版本。

Create the file at some level above the other projects, in terms of structure, then add it to all projects (from within Visual Studio), but when doing so be sure to select 'Add as link'.就结构而言,在其他项目上方的某个级别创建文件,然后将其添加到所有项目(从 Visual Studio 中),但这样做时请确保 select '添加为链接'。

I've used an MSBuild task to handle the updating, too, I just can't think of it - which build engine do you use?我也使用了 MSBuild 任务来处理更新,我只是想不出 - 你使用哪个构建引擎?

You can theoretically have one single assembly file.理论上,您可以拥有一个程序集文件。 Just link the file in all other projects: Add existing file >> link file instead of adding (button dropdown)只需在所有其他项目中链接文件:添加现有文件>>链接文件而不是添加(按钮下拉菜单)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM