What does the GUID in C# Programs in the AssemblyInfo.cs? [duplicate]

半城伤御伤魂 提交于 2020-12-02 04:57:44

问题


I'm wondering for what the GUID in the AssemblyInfo.cs in C# Programs is: [assembly: Guid("a4df9f47-b2d9-49a9-b237-09220857c051")]

The commentary says it's for COM objects, but why do they need a GUID? Is the GUID accessibly externally?

So if it's only for COMs, do you need a GUID when you set [assembly: ComVisible(false)]?


回答1:


Guid (Globally unique identifier) is used to identify your component by outside world. When you write a project which is going to be used as COM (Component Object Model) you will have to give a unique name. For this reason you need to apply GUID attribute.

More info at http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.guidattribute.aspx

You can remove it if you won't be exposing it as COM on assembly level




回答2:


All .Net assemblies have a GUID.
This attribute sets it; otherwise, it will be randomly generated by the compiler.

This GUID is not used by much.



来源:https://stackoverflow.com/questions/22516400/what-does-the-guid-in-c-sharp-programs-in-the-assemblyinfo-cs

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!