如何在Visual Studio中更改所有文件的版本

7

我在Visual Studio中有一个解决方案,其中包含许多项目和DLL文件,如何在构建之前或之后更改解决方案中所有文件(dll和exe文件)的版本号?

[解决方案信息

[程序集信息


3
你可以创建一个名为 SharedAssemblyInfo.cs 的文件,并在每个项目中链接它,这样在一个地方更改它会同时更改所有项目的内容。 - Ron Beyer
你在第一张截图中找到的信息是从哪里获取的?我不熟悉在哪里查看那些信息。 - Kritner
@RonBeyer 我熟悉程序集信息(第二张截图),我只是不确定第一张截图是在哪里查看的。 - Kritner
除了Visual Studio之外,它是标准Windows文件属性对话框的一部分。 - Ron Beyer
3- RonBeyer:第一个屏幕在:右键单击dll文件——>属性——>详细信息。 - SLEO
显示剩余6条评论
4个回答

4

可以通过编辑项目解决方案资源管理器中属性下可见的Assemblyinfo.cs文件来更改程序集信息,这里您可以更改程序集版本。

using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following 
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("My App Title")]
[assembly: AssemblyDescription("App Description")]
[assembly: AssemblyCompany("My Company Name")]
[assembly: AssemblyProduct("ConsoleApp")]
[assembly: AssemblyCopyright("Copyright © 2015")]
[assembly: AssemblyTrademark("My Company Trademark")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible 
// to COM components.  If you need to access a type in this assembly from 
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("513436d3-aa2f-407b-83d2-9268300cc373")]

// Version information for an assembly consists of the following four values:
//
//      Major Version
//      Minor Version 
//      Build Number
//      Revision
//
// You can specify all the values or you can default the Build and Revision Numbers 

//*******Assembly Version can be changed here*********
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

或者

  • 进入“解决方案资源管理器”(Solution Explorer)
  • 右键单击您的项目
  • 选择“属性”
  • 在弹出的窗口中,点击“程序集信息”(Assembly Information)
  • 在弹出框中,您可以编辑与程序集相关的详细信息
  • 单击“确定”,您的AssemblyInfo.cs文件将自动更新

    弹出框,在其中您可以编辑程序集相关的详细信息


3

我知道这是一个比较老的问题,但是这里有一篇关于如何管理多个程序集解决方案版本的好文章。

https://jonthysell.com/2017/01/10/automatically-generating-version-numbers-in-visual-studio/

这显示了在AssemblyInfo.cs文件中管理版本控制的三个选项。

  1. 使用内置通配符运算符自动生成构建和发布号码,但仍需要手动更新主要版本和次要版本。
  2. 使用第三方Visual Studio扩展程序。
  3. 使用在解决方案中所有项目之间共享的模板文件(*.tt)来自定义基于是预览还是生产发布生成数字的方式。

我发现对于我的应用程序,选项3最有用且最容易维护,因为您可以在所有程序集之间共享单个文件,并轻松地自定义数字以匹配您的特定情况。


你能否在链接更改的情况下,请在此处总结文章中最相关的部分? - ForeverZer0
1
@ForeverZer0 已更新。如果这个细节水平足够,请让我知道。我正在尝试在不重写链接文章的情况下进行总结。 - Rickchip

1

正如AssemblyInfo.cs中的注释所指出的那样,如果您要更改:

// Version information for an assembly consists of the following four values:
//
//      Major Version
//      Minor Version 
//      Build Number
//      Revision
//
// You can specify all the values or you can default the Revision and Build Numbers 
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

to:

// Version information for an assembly consists of the following four values:
//
//      Major Version
//      Minor Version 
//      Build Number
//      Revision
//
// You can specify all the values or you can default the Revision and Build Numbers 
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.0.*")]

每次构建后,程序集将获得一个新的版本号/修订号。
来自MSDN
您可以指定所有值,也可以使用星号(*)接受默认的构建号、修订号或两者。例如,[assembly:AssemblyVersion("2.3.25.1")] 表示 2 为主版本,3 为次版本,25 为构建号,1 为修订号。版本号 [assembly:AssemblyVersion("1.2.*")] 指定 1 为主版本,2 为次版本,并接受默认的构建和修订号。版本号 [assembly:AssemblyVersion("1.2.15.*")] 指定 1 为主版本,2 为次版本,15 为构建号,并接受默认的修订号。默认的构建号每天递增。默认的修订号是当地时间午夜后的秒数(不考虑夏令时的时区调整),除以 2。
共享程序集信息的教程:

http://theburningmonk.com/2010/03/net-tips-use-a-shared-assemblyinfo-cs-for-your-solution/

  1. 在解决方案的根目录下创建一个名为SharedAssemblyInfo.cs的文件,并将所有通用设置放置在其中。
  2. 右键单击您的项目并选择“添加现有项...”,浏览到SharedAssemblyInfo.cs,并确保选择“添加为链接”。

我已经做过了,但问题在于只有在构建后exe文件被更新,而我想要的是dll文件也随着exe的变化而改变。 - SLEO
任何与您的 EXE 一起构建的 DLL 都是具有自己的 AssemblyInfo 类的单独程序集。您确定要所有依赖的 DLL 具有相同的版本号吗?当这些 DLL 用于具有自己版本号的不同 EXE 时会发生什么?版本适用于程序集,而不是应用程序(一般而言)。 - Kritner
我需要这样做是因为我想为所有文件(dll和exe)生成特定版本的应用程序发布,而我的老板要求我这样做。 - SLEO

0

这是一个适用于asp.net应用程序的简单解决方案。

进入项目属性 => 应用程序(选项卡)(参见下面的图像)


点击"程序集信息",你会找到"程序集版本"和"文件版本"。

enter image description here


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接