visual-studio 更新解决方案中所有程序集的版本号
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/759644/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Updating the version number of all assemblies in a solution
提问by PaulB
I've got a rather large solution in Visual Studio. Is there a way to update the Major / Minor version numbers for all the assemblies in the solution in one go?
我在 Visual Studio 中有一个相当大的解决方案。有没有办法一次性更新解决方案中所有程序集的主要/次要版本号?
回答by grover
You can share an AssemblyInfo.cs file between all projects in the solution. This shared file should contain the version numbers. To share it, you must use Add Existing File in VS and select Add as Link in the file dialog. Every project has its private and the shared AssemblyInfo.cs. The private one still contains the non-Version attributes.
您可以在解决方案中的所有项目之间共享 AssemblyInfo.cs 文件。此共享文件应包含版本号。要共享它,您必须在 VS 中使用添加现有文件并在文件对话框中选择添加为链接。每个项目都有其私有的和共享的 AssemblyInfo.cs。私有的仍然包含非版本属性。
I've got a TeamCity setup, where I'm generating the shared file in each TeamCity build using the actual build version and it works beautifully.
我有一个 TeamCity 设置,我使用实际的构建版本在每个 TeamCity 构建中生成共享文件,它运行良好。
回答by marijne
We have a single AssemblyInfoCommon.cs which has the version numbers, and is included in each project by reference. The other AssemblyInfo.cs files remain but only contain the assembly-specific information (title and description). So we only have one file to update for every C# project.
我们有一个包含版本号的 AssemblyInfoCommon.cs,并通过引用包含在每个项目中。其他 AssemblyInfo.cs 文件保留但仅包含特定于程序集的信息(标题和描述)。因此,对于每个 C# 项目,我们只有一个文件要更新。
回答by driis
You can also have a public const string in one of your classes, that represents the build number, and use it in all your AssemblyInfo.cs for the different projects. Of course this would have to be in a project that are referenced by all the other projects, in order to work.
您还可以在您的一个类中拥有一个公共常量字符串,它表示内部版本号,并在您的所有 AssemblyInfo.cs 中为不同的项目使用它。当然,这必须在所有其他项目引用的项目中才能工作。
It is a good option, if you don't like the idea to reference the same AssemblyInfo.cs in all your projects.
这是一个不错的选择,如果您不喜欢在所有项目中引用相同的 AssemblyInfo.cs 的想法。
Edit: Note! This also works when you use multiple languages (F# and C# in my case).
编辑:注意!当您使用多种语言(在我的例子中是 F# 和 C#)时,这也适用。
回答by Lasse V. Karlsen
Search/Replace?
搜索/替换?
The version numbers are stored in text-files after all (AssemblyInfo.cs under the Properties folder for each project).
毕竟,版本号存储在文本文件中(每个项目的 Properties 文件夹下的 AssemblyInfo.cs)。
回答by Lasse V. Karlsen
There is a very useful utility I used some time ago on a project which required highly managed versioning:
我前段时间在一个需要高度管理版本控制的项目中使用了一个非常有用的实用程序:
http://www.codeproject.com/KB/macros/versioningcontrolledbuild.aspx
http://www.codeproject.com/KB/macros/versioningControlledbuild.aspx
回答by Toras
Also you can create some "core" assembly and add into each your assembly reference to "core" assembly. "core" assembly will constaint constant. In this case in each Assembly info file will be set asembly version from "core" constant. For example:
您也可以创建一些“核心”程序集并将其添加到每个程序集对“核心”程序集的引用中。“核心”程序集将保持不变。在这种情况下,每个程序集信息文件将从“核心”常量中设置程序集版本。例如:
"core" assembly has file Ver.cs with constant: public const string Value = "0.0.0.99";
“核心”程序集具有带有常量的文件 Ver.cs:public const string Value = "0.0.0.99";
in each solution assembly info will: [assembly: AssemblyFileVersion(Ver.Value)]
在每个解决方案中,程序集信息将:[程序集:AssemblyFileVersion(Ver.Value)]

