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

C# 如何更改Visual Studio中所有文件的版本,c#,visual-studio,version,assemblyinfo,C#,Visual Studio,Version,Assemblyinfo,我在Visual Studio中有一个解决方案,它有许多项目和DLL文件, 如何在生成之前或之后更改解决方案中所有文件(dll和exe文件)的版本 [ [正如AssemblyInfo.cs中的注释所指出的,如果您要更改: // Version information for an assembly consists of the following four values: // // Major Version // Minor Version // Build

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

[


[

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

每次生成后,程序集将获得新的生成编号/修订

发件人:

您可以指定所有值,也可以使用星号()接受默认版本号和/或修订号。例如,[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

关于共享部件信息的教程:

  • 在解决方案的根目录中创建一个文件,比如SharedAssemblyInfo.cs,并将所有常用设置放在那里
  • 右键单击项目并添加现有项…,浏览至SharedAssemblyInfo.cs,并确保选择“添加为”链接

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

    • 转到解决方案资源管理器
    • 右键单击您的项目
    • 选择属性
    • 在出现的窗口中,单击“部件信息”
    • 在弹出框中,可以编辑与部件相关的详细信息
    • 单击“确定”,您的AssemblyInfo.cs文件将被更新 自动地


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

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

  • 使用内置通配符运算符自动生成 生成和发布编号,仍然需要手动更新 主要版本和次要版本
  • 使用第三方Visual Studio扩展
  • 使用在中的所有项目之间共享的模板文件(*.tt) 该解决方案可自定义如何基于 无论是预览版还是制作版

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

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

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


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


    你可以创建一个
    SharedAssemblyInfo.cs
    文件,并在每个项目中链接它,这样在一个地方更改它会在所有项目中更改它。你在哪里找到第一个屏幕截图中发布的信息?我不熟悉在哪里查看它information@Kritner如果展开(而不是双击)在properties文件夹中,有一个名为“AssemblyInfo.cs”的文件包含该信息。另一个屏幕截图是右键单击DLL并选择“properties>Details”。@RonBeyer我熟悉AssemblyInfo(第二个屏幕截图)我只是不确定第一个屏幕截图是从哪里查看的。它是标准windows文件属性对话框的一部分,除了Visual Studio。它会的,我也这样做了,但问题是生成后只更新了exe文件,我想要的是将dll文件更改为exe changedany
    dll
    s,这是使用
    E生成的XE
    是具有各自AssemblyInfo类的独立程序集。是否确实希望所有依赖的
    DLL
    s具有相同的版本号?当这些
    DLL
    s用于具有自己版本号的独立
    EXE
    s时会发生什么?版本适用于程序集,而不是应用程序(一般来说)我需要它,因为我想为所有文件(dll和exe)生成具有特定版本的应用程序的发行版,我的老板让我做这件事,你能在这里总结一下文章中最相关的部分吗?@ForeverZer0已更新。让我知道这一级别的细节是否足够。我正在尝试总结,但不重写链接的文章。
    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")]