.net AssemblyInfo.cs 有什么用?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13180543/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 16:41:25  来源:igfitidea点击:

What is AssemblyInfo.cs used for?

.net

提问by Sachin Kainth

My question is pretty basic. What I'd like to know is what is the AssemblyInfo.cs file used for?

我的问题很基本。我想知道的是 AssemblyInfo.cs 文件的用途是什么?

采纳答案by Francois

AssemblyInfo.cs contains information about your assembly, like name, description, version, etc. You can find more details about its content reading the comments that are included in it.

If you delete it, your assembly will be compiled with no information, i.e., in the Details tab of the file properties you will see no name, no description, version 0.0.0.0, etc.

The value associated with assembly:Guid is the ID that will identify the assembly if it will be exposed as a COM object. So, if your assembly isn't COM-exposed, you don't need this. It is randomly generate. In any case, normally, you don't need to modify it.

AssemblyInfo.cs 包含有关您的程序集的信息,如名称、描述、版本等。您可以通过阅读其中包含的注释找到有关其内容的更多详细信息。

如果您删除它,您的程序集将在编译时没有任何信息,即,在文件属性的“详细信息”选项卡中,您将看不到名称、描述、版本 0.0.0.0 等。

与程序集关联的值:Guid 是标识程序集(如果程序集将作为 COM 对象公开)的 ID。所以,如果你的程序集不是 COM 公开的,你就不需要这个。它是随机生成的。在任何情况下,通常都不需要修改它。

Credits goes to : http://social.msdn.microsoft.com/Forums/en/csharpgeneral/thread/8955449f-71ac-448e-9ee6-5329fceecd3c

学分转到:http: //social.msdn.microsoft.com/Forums/en/csharpgeneral/thread/8955449f-71ac-448e-9ee6-5329fceecd3c

回答by Rahul Tripathi

In AssemblyInfo file Informational Attributes contains the information about product Name, description, Trademark, copyright. In general this information's are either hardcode or store in database or flat file. .NET assembly provides to store this information in AssemblyInfo file and after compilation it becomes the part of assembly. So at run time one can read this information.

在 AssemblyInfo 文件中,信息属性包含有关产品名称、描述、商标、版权的信息。一般来说,这些信息要么是硬编码,要么存储在数据库或平面文件中。.NET 程序集提供将此信息存储在 AssemblyInfo 文件中,并在编译后成为程序集的一部分。所以在运行时可以读取这些信息。

Part of Assembly Information

组装信息的一部分

1 AssemblyTitle : Title name from the assembly.

1 AssemblyTitle :来自程序集的标题名称。

2 AssemblyDescription: It provides the detail description from the assembly.

2 AssemblyDescription:它提供来自程序集的详细描述。

3 AssemblyCompany: It Provides the company information from the assembly.

3 AssemblyCompany:它提供来自程序集的公司信息。

4 AssemblyProduct: It provides the production information from the assembly.

4 AssemblyProduct:提供装配体的生产信息。

5 AssemblyCopyright: It Provides the copyright from the assembly.

5 AssemblyCopyright:提供程序集的版权。

6 AssemblyTrademark: It Provides the trademark from the assembly.

6 AssemblyTrademark:它提供来自程序集的商标。

Each of these attributes has a defined class, which is used to read the information from the AssemblyInfo file.

这些属性中的每一个都有一个定义的类,用于从 AssemblyInfo 文件中读取信息。

Check out this link:- http://www.dotnetspider.com/forum/157292-assemblyinfo-file.aspx

查看此链接:- http://www.dotnetspider.com/forum/157292-assemblyinfo-file.aspx

回答by Kendall Frey

Go to your Project Properties, the Application tab, and click the Assembly Information button.

转到您的项目属性,应用程序选项卡,然后单击程序集信息按钮。

That's what is stored in AssemblyInfo.cs.

这就是 AssemblyInfo.cs 中存储的内容。

In Windows Explorer, right click your project's .exe output, select Properties, and go to the Details tab. That is the information generated by AssemblyInfo.cs.

在 Windows 资源管理器中,右键单击项目的 .exe 输出,选择属性,然后转到详细信息选项卡。那就是AssemblyInfo.cs 生成的信息。

回答by ParPar

In AssemblyInfo file you can store informations which you can get from every place in the project, so you don't have to update all the places but just the assemblyInfo.

在 AssemblyInfo 文件中,您可以存储可以从项目中每个位置获取的信息,因此您不必更新所有位置,而只需更新 assemblyInfo。

For example - in this file you update the version number, and it is updated automatically in your site. In the html page, to get the version number, write:

例如 - 在此文件中您更新版本号,它会在您的站点中自动更新。在 html 页面中,要获取版本号,请编写:

Assembly assembly = Assembly.GetAssembly(typeof(ProjectName.WebSite.Controllers.MyController));
string version = assembly.GetName().Version.ToString();

and it will be updated each time you upload a new version.

每次上传新版本时都会更新。

回答by Oded

It is a convenient location for assembly level attributes, such as the version, company name etc.

它是程序集级别属性的方便位置,例如版本、公司名称等。

回答by Collins A. Eban

This file contains general information about the application you are building, some of these information includes the title of your application, copyright etc, for instance if the title of your application is "MyApplication" you should see something like this: assembly: AssemblyTitle("MyApplication")]

此文件包含有关您正在构建的应用程序的一般信息,其中一些信息包括您的应用程序的标题、版权等,例如,如果您的应用程序的标题是“MyApplication”,您应该看到如下内容: assembly: AssemblyTitle("我的应用程序”)]