How do I programmatically get the GUID of an appli

2019-01-08 17:55发布

I need to access the assembly of my project in C# .NET2.0.

I can see the GUID in the 'Assembly Information' dialog in under project properties, and at the moment I have just copied it to a const in the code. The GUID will never change, so this is not that bad of a solution, but it would be nice to access it directly. Is there a way to do this?

7条回答
Luminary・发光体
2楼-- · 2019-01-08 18:48

Another way is to use Marshal.GetTypeLibGuidForAssembly.

According to msdn:

When assemblies are exported to type libraries, the type library is assigned a LIBID. You can set the LIBID explicitly by applying the System.Runtime.InteropServices.GuidAttribute at the assembly level, or it can be generated automatically. The Tlbimp.exe (Type Library Importer) tool calculates a LIBID value based on the identity of the assembly. GetTypeLibGuid returns the LIBID that is associated with the GuidAttribute, if the attribute is applied. Otherwise, GetTypeLibGuidForAssembly returns the calculated value. Alternatively, you can use the GetTypeLibGuid method to extract the actual LIBID from an existing type library.

查看更多
登录 后发表回答