- DemoEXE:開來抓 GUID 用,本身沒有寫任何 Code
- DemoShowGUID:要在這裡抓 DemoEXE 和本身的 GUID 資訊
using System.Runtime.InteropServices;
using System.Reflection;
namespace DemoShowGUID
{
class Program
{
static void Main(string[] args)
{
// DemoEXE GUID:3088714c-9fa3-4d6a-8a00-2e743b93c09b
string path = @"D:\Reflection_AssemblyInfo\DemoEXE\bin\Debug\DemoEXE.EXE";
string DemoEXEInfo = ((GuidAttribute)Assembly.LoadFrom(path).GetCustomAttributes(typeof(GuidAttribute), false).GetValue(0)).Value;
// 抓本身 DemoShowGUID GUID:6fa73d73-6533-4d4c-9fcb-100a6b43b0cc
string DemoShowInfo = ((GuidAttribute)Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(GuidAttribute), false).GetValue(0)).Value;
string message =
"DemoEXE GUID 資訊:" + DemoEXEInfo + Environment.NewLine +
"DenoShowInfo GUID 資訊:" + DemoShowInfo;
Console.WriteLine(message);
}
}
}
DemoEXE Assembly 資訊
DemoShowGUID Assembly 資訊
結果
- 參考資料
- 日文網路文章




沒有留言:
張貼留言