using System.Reflection;
using System.Runtime.InteropServices;
代码:
Attribute guid_attr = Attribute.GetCustomAttribute(Assembly.GetExecutingAssembly(), typeof(GuidAttribute));
string guid = ((GuidAttribute)guid_attr).Value;
这个ID就是项目属性里程序集信息窗口上显示的那个GUID,只要不改项目,这个GUID就不变。
网上看到有兄弟用的如下方法,列出来供参考(此方法只能取针对某版本的GUID,每编译一次都会变)
Assembly assembly = Assembly.LoadFile(exePath);
string guid=assembly.ManifestModule.ModuleVersionId.ToString();