如何以编程方式获取.NET 2.0中应用程序的GUID [英] How do I programmatically get the GUID of an application in .NET 2.0

查看:86
本文介绍了如何以编程方式获取.NET 2.0中应用程序的GUID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在C#.NET 2.0中访问我的项目的程序集.

I need to access the assembly of my project in C# .NET 2.0.

我可以在项目属性下的汇编信息"对话框中看到GUID,此刻,我刚刚将其复制到了代码中的const中.GUID永远不会更改,因此这不是解决方案的坏问题,但是直接访问它会很好.有办法吗?

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?

推荐答案

尝试以下代码.您要查找的值存储在附加到Assembly的GuidAttribute实例上

Try the following code. The value you are looking for is stored on a GuidAttribute instance attached to the Assembly

using System.Runtime.InteropServices;

static void Main(string[] args)
{
    var assembly = typeof(Program).Assembly;
    var attribute = (GuidAttribute)assembly.GetCustomAttributes(typeof(GuidAttribute),true)[0];
    var id = attribute.Value;
    Console.WriteLine(id);
}

这篇关于如何以编程方式获取.NET 2.0中应用程序的GUID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆