What are the best practices for using Assembly Attributes?

后端 未结 8 1247
北荒
北荒 2020-12-12 09:16

I have a solution with multiple project. I am trying to optimize AssemblyInfo.cs files by linking one solution wide assembly info file. What are the best practices for doing

相关标签:
8条回答
  • 2020-12-12 09:40

    In my case, we're building a product for which we have a Visual Studio solution, with various components in their own projects. The common attributes go. In the solution, there are about 35 projects, and a common assembly info (CommonAssemblyInfo.cs), which has the following attributes:

    [assembly: AssemblyCompany("Company")]
    [assembly: AssemblyProduct("Product Name")]
    [assembly: AssemblyCopyright("Copyright © 2007 Company")]
    [assembly: AssemblyTrademark("Company")]
    
    //This shows up as Product Version in Windows Explorer
    //We make this the same for all files in a particular product version. And increment it globally for all projects.
    //We then use this as the Product Version in installers as well (for example built using Wix).
    [assembly: AssemblyInformationalVersion("0.9.2.0")]
    

    The other attributes such as AssemblyTitle, AssemblyVersion etc, we supply on a per-assembly basis. When building an assembly both AssemblyInfo.cs and CommonAssemblyInfo.cs are built into each assembly. This gives us the best of both worlds where you may want to have some common attributes for all projects and specific values for some others.

    Hope that helps.

    0 讨论(0)
  • 2020-12-12 09:42

    Using a single AseemblyInfo.cs file for multiple projects is not recommended. The AssemblyInfo file includes information that might be relevant only for that specific assembly. The two most obvious pieces of information are the AssemblyTitle and AssemblyVersion.

    A better solution might be to use targets file, which are handled by the MSBuild, in order to "inject" assembly attributes to more than one project.

    0 讨论(0)
提交回复
热议问题