How do I programmatically get the GUID of an application in .net2.0

前端 未结 7 1116
囚心锁ツ
囚心锁ツ 2020-11-29 18:52

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

7条回答
  •  盖世英雄少女心
    2020-11-29 19:36

    You should be able to read the Guid attribute of the assembly via reflection. This will get the GUID for the current assembly

             Assembly asm = Assembly.GetExecutingAssembly();
            var attribs = (asm.GetCustomAttributes(typeof(GuidAttribute), true));
            Console.WriteLine((attribs[0] as GuidAttribute).Value);
    

    You can replace the GuidAttribute with other attributes as well, if you want to read things like AssemblyTitle, AssemblyVersion etc

    You can also load another assembly (Assembly.LoadFrom and all) instead of getting the current assembly - if you need to read these attributes of external assemblies (eg - when loading a plugin)

提交回复
热议问题