In a project created by Visual Studio, a file called "AssemblyInfo.cs", which describes the assembly generated by the project, will be also automatically created. And it's very common that there is more than one project in a solution. Therefore, there will be many "AssemblyInfo.cs" existing in a solution. However, the contents of these "AssemblyInfo.cs" are more or less the same. It's a type of duplication for sure. We'd better extract all the duplicated code into a global file shared by all the projects.

The image describes the scenario: in a solution, there is a global file called "GlobalAssemblyInfo.cs" which describes assemblies generated by all the projects, and every project holds a reference to the global file. Share a GlobalAssemblyInfo.cs among projects in a solution

Steps:

  • Create a file called "GlobalAssemblyInfo.cs";
  • Add the file to the solution as a solution item;
  • Open the global file, Write appropriate codes in it. Sample:
     1Share a GlobalAssemblyInfo.cs among projects in a solutionusing System;
     2Share a GlobalAssemblyInfo.cs among projects in a solutionusing System.Reflection;
     3Share a GlobalAssemblyInfo.cs among projects in a solutionusing System.Runtime.InteropServices;
     4Share a GlobalAssemblyInfo.cs among projects in a solution
     5Share a GlobalAssemblyInfo.cs among projects in a solution[assembly : ComVisible(false)]
     6Share a GlobalAssemblyInfo.cs among projects in a solution[assembly : CLSCompliant(true)]
     7Share a GlobalAssemblyInfo.cs among projects in a solution[assembly : AssemblyProduct("Share a GlobalAssemblyInfo.cs among projects in a solution.")]
     8Share a GlobalAssemblyInfo.cs among projects in a solution[assembly : AssemblyCompany("Company name")]
     9Share a GlobalAssemblyInfo.cs among projects in a solution[assembly : AssemblyVersion("1.0.0.0")]
    10Share a GlobalAssemblyInfo.cs among projects in a solution#if DEBUG
    11Share a GlobalAssemblyInfo.cs among projects in a solution[assembly : AssemblyConfiguration("Debug")]
    12Share a GlobalAssemblyInfo.cs among projects in a solution#else
    13Share a GlobalAssemblyInfo.cs among projects in a solution[assembly : AssemblyConfiguration("Release")]
    14Share a GlobalAssemblyInfo.cs among projects in a solution#endif
    15Share a GlobalAssemblyInfo.cs among projects in a solution[assembly : AssemblyCopyright("")]
    16Share a GlobalAssemblyInfo.cs among projects in a solution[assembly : AssemblyTrademark("")]
    17Share a GlobalAssemblyInfo.cs among projects in a solution[assembly : AssemblyCulture("")]
  • Open a project file(.csproj, etc.) in a text editor, append the following section to the <Files>/<Include> element.
    1Share a GlobalAssemblyInfo.cs among projects in a solution<File
    2Share a GlobalAssemblyInfo.cs among projects in a solution  RelPath = "GlobalAssemblyInfo.cs"
    3Share a GlobalAssemblyInfo.cs among projects in a solution  Link = "..\Common\GlobalAssemblyInfo.cs"
    4Share a GlobalAssemblyInfo.cs among projects in a solution  SubType = "Code"
    5Share a GlobalAssemblyInfo.cs among projects in a solution  BuildAction = "Compile"
    6Share a GlobalAssemblyInfo.cs among projects in a solution/>

相关文章:

  • 2022-01-07
  • 2021-04-19
  • 2021-06-24
  • 2021-11-30
  • 2021-04-21
  • 2022-12-23
  • 2022-01-24
  • 2021-12-24
猜你喜欢
  • 2022-12-23
  • 2018-04-27
  • 2021-12-25
  • 2022-12-23
  • 2018-05-07
  • 2022-01-25
相关资源
相似解决方案