繁体   English   中英

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

[英]How to change the version of all files in Visual Studio

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

[解决方案信息

[装配信息

可以通过编辑 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")]

或者

我知道这是一个较旧的问题,但这里有一篇关于在具有多个程序集的解决方案中管理版本的精彩文章。

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

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

  1. 使用内置通配符自动生成 Build 和 Release 编号,这仍然需要手动更新 Major 和 Minor 版本。
  2. 使用第 3 方 Visual Studio 扩展。
  3. 使用在解决方案中的所有项目之间共享的模板文件 (*.tt),根据它是预览版还是生产版来自定义如何生成数字。

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

正如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")]

到:

// 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,并确保您选择添加为链接。

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

转到项目属性=>应用程序(选项卡)(请参阅下图以供参考)


单击程序集信息,您将在那里找到程序集版本文件版本

在此处输入图片说明

暂无
暂无

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

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