我需要在 C# 中访问我的项目的程序集。
我可以在项目属性下的“程序集信息”对话框中看到 GUID,目前我刚刚将其复制到代码中的 const 中。 GUID 永远不会改变,所以这并不是一个糟糕的解决方案,但直接访问它会更好。有没有办法做到这一点?
尝试以下代码。您正在寻找的值存储在GuidAttribute
实例附加到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);
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)