一个解决方案下的多个项目共享一个AssemblyInfo

http://stackoverflow.com/questions/18963750/add-file-as-a-link-on-visual-studio-debug-vs-publish

http://stackoverflow.com/questions/2593612/visual-studio-add-item-add-as-link-rather-than-just-add

 

http://blogs.msdn.com/b/jjameson/archive/2009/04/02/linked-files-in-visual-studio-solutions.aspx

http://blogs.msdn.com/b/jjameson/archive/2009/04/03/shared-assembly-info-in-visual-studio-projects.aspx

需要注意的是,有一个文件名为GlobalAssemblyInfo.cs的文件,这个文件是通过添加链接的方式加入项目的

添加方法为:在项目上右键,添加,现有项,最后选中文件,之后的添加按钮有一个小箭头,点一下,出来菜单,选择添加为链接

 

A couple of years ago, I wrote a post introducing my system for structuring Visual Studio solutions. However, I apparently forgot to post a follow-up providing additional details, such as configuring assembly versioning and what I like to call "shared assembly information."

Before I can cover these details, I need to first ensure that you are familiar with the concept of linking files in Visual Studio solutions, why this is a powerful feature, and when to use it.

If you ever used Visual SourceSafe (VSS), you likely used its feature for sharing files across multiple projects. For example, you could check-in a file at the root of your solution, and then drag-and-drop it into other projects (i.e. "subfolders") in your solution. Thus, whenever a change was made to the file (regardless of which particular VSS project the change was made in), the next time you "got latest" the change would be reflected in all locations. This was a common way of, for example, having all of your .NET assemblies in the same Visual Studio solution specify the same assembly version.

 

Note that Team Foundation Server (TFS) does not provide an equivalent "share file" feature. Fortunately, however, you no longer need such a feature.

Back in the days of the original Visual Studio .NET and the following version, Visual Studio .NET 2003, whenever you added an existing file to a project, it copied the file into the corresponding location in the project.

However, in Visual Studio 2005, the Add Existing Item feature provided the ability to choose to either Add the item or Add As Link (via the little down arrow on the button in the dialog box).

In other words, once you upgraded to Visual Studio 2005, it was no longer necessary to rely on any "sharing" features of your source control system in order to have multiple projects always reference the latest version of a file.

 

Note that when you Add an item in Visual Studio 2005 or Visual Studio 2008, the behavior is the same as earlier versions (meaning the file is copied into the corresponding location within the project). When you choose to Add As Link, however, you simply reference the file in-place. [Don't worry, relative paths ensure that everyone on your team is free to choose whatever root folder they wish for their individual workspaces.]

To illustrate this concept, I quickly built out a "demo" solution, as shown below.

In Windows Explorer, the corresponding folder structure looks like this:

The corresponding folder structure on disk resembles the following:

  • Fabrikam
    • Demo
      • Dev (branch)
        • Lab1 (branch)
          • AssemblyVersionInfo.cs
          • CustomDictionary.xml
          • Fabrikam.Demo.sln
          • Fabrikam.Demo.snk
          • SharedAssemblyInfo.cs
          • AdminConsole
            • AdminConsole.csproj
            • Program.cs
            • Properties
              • AssemblyInfo.cs
          • CoreServices
            • CoreServices.csproj
            • Logging
              • Logger.cs
            • Properties
              • AssemblyInfo.cs

Note that AssemblyVersionInfo.csCustomDictionary.xmlFabrikam.Demo.snk, and SharedAssemblyInfo.csreside in the same folder as the Visual Studio solution file and are subsequently "linked into" the two Visual C# projects. Thus whenever a change is made to one of these files, the next build of each project will reflect that change.

With this foundation in place, I'll explain some other recommended best practices over a series of follow-up posts, including:

Stay tuned!

 

需要注意的是:

GlobalAssemblyInfo.cs文件需要单独用一个文件夹SolutionItems来存放,此文件夹和解决方案下的其他项目平级

 

 

2015年07月03日,发现了新的资源

What are the best practices for using Assembly Attributes?

We're using a global file called GlobalAssemblyInfo.cs and a local one called AssemblyInfo.cs. The global file contains the following attributes:

[assembly: AssemblyProduct("Your Product Name")] [assembly: AssemblyCompany("Your Company")] [assembly: AssemblyCopyright("Copyright © 2008 ...")] [assembly: AssemblyTrademark("Your Trademark - if applicable")] #if DEBUG [assembly: AssemblyConfiguration("Debug")] #else [assembly: AssemblyConfiguration("Release")] #endif [assembly: AssemblyVersion("This is set by build process")] [assembly: AssemblyFileVersion("This is set by build process")]

The local AssemblyInfo.cs contains the following attributes:

[assembly: AssemblyTitle("Your assembly title")] [assembly: AssemblyDescription("Your assembly description")] [assembly: AssemblyCulture("The culture - if not neutral")] [assembly: ComVisible(true/false)] // unique id per assembly [assembly: Guid("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx")]

You can add the GlobalAssemblyInfo.cs using the following procedure:

  • Select Add/Existing Item... in the context menu of the project
  • Select GlobalAssemblyInfo.cs
  • Expand the Add-Buton by clicking on that little down-arrow on the right hand
  • Select "Add As Link" in the buttons drop down list

转载于:https://www.cnblogs.com/chucklu/p/4596304.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在 VS2022 中创建的控制台应用程序默认不包含 `AssemblyInfo.cs` 文件,但是可以手动添加该文件来指定程序的元数据信息。下面是一个可能的 `AssemblyInfo.cs` 文件的示例: ```csharp using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; // 程序集的常规信息由以下属性集控制。 // 更改这些属性值以修改与程序集相关联的信息。 [assembly: AssemblyTitle("ConsoleApp1")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("ConsoleApp1")] [assembly: AssemblyCopyright("Copyright ©")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] // 设置 ComVisible 为 false 使此程序集中的类型对 COM 组件不可见。 // 如果需要从 COM 访问此程序集中的类型,则将 ComVisible 属性设置为 true。 [assembly: ComVisible(false)] // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID [assembly: Guid("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX")] // 程序集的版本信息由以下四个值组成: // // 主版本 // 次版本 // 生成号 // 修订号 // // 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,方法是按如下所示使用 '*': // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("1.0.0.0")] [assembly: AssemblyFileVersion("1.0.0.0")] ``` 在这个示例中,`AssemblyTitle`、`AssemblyDescription`、`AssemblyConfiguration`、`AssemblyCompany`、`AssemblyProduct`、`AssemblyTrademark`、`AssemblyCulture` 等属性用于设置程序集的元数据信息,如程序的名称、描述、版本、版权信息等。`ComVisible` 属性用于设置程序集是否对 COM 组件可见。`Guid` 属性用于设置程序集的唯一标识符。`AssemblyVersion` 和 `AssemblyFileVersion` 属性用于设置程序集的版本号信息。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值