,你可以看看這裏:
「Programmatically check if an assembly is loaded in GAC with C#」
如果鏈接轉壞:
public static bool AssemblyExist(string assemblyname, out string response)
{
try
{
response = QueryAssemblyInfo(assemblyname);
return true;
}
catch (System.IO.FileNotFoundException e)
{
response = e.Message;
return false;
}
}
// If assemblyName is not fully qualified, a random matching may be
public static String QueryAssemblyInfo(string assemblyName)
{
var assembyInfo = new AssemblyInfo {cchBuf = 512};
assembyInfo.currentAssemblyPath = new String('', assembyInfo.cchBuf);
IAssemblyCache assemblyCache;
// Get IAssemblyCache pointer
var hr = GacApi.CreateAssemblyCache(out assemblyCache, 0);
if (hr == IntPtr.Zero)
{
hr = assemblyCache.QueryAssemblyInfo(1, assemblyName, ref assembyInfo);
if (hr != IntPtr.Zero)
{
Marshal.ThrowExceptionForHR(hr.ToInt32());
}
}
else
{
Marshal.ThrowExceptionForHR(hr.ToInt32());
}
return assembyInfo.currentAssemblyPath;
}
可能重複:http://stackoverflow.com/questions/689072/how-to-check-if-a-dll-is-registered或http://stackoverflow.com/問題/ 377551/physicalinstalled -dll-installed-to-the-gac的路徑 –
根據它給出的程序集包含當前正在執行的代碼。但我需要特定的DLL。 – DevT
通過使用註冊表我們不能這樣做。 :) – DevT