[英]C#: finding path to PresentationCore.dll (and other assemblies) in the GAC
我需要通過調用ReferencedAssemblies.Add
來引用CSharpCodeProvider
各種程序集。
對於某些程序集,只需傳遞程序集名稱就足夠了-例如ReferencedAssemblies.Add("System.dll")
。
但是, PresentationCore.dll
是其中需要程序集完整路徑的程序之一-我可能不一定在目標計算機上知道。
如何找到(最新?)各個程序集的確定路徑-例如,在GAC中?
理想情況下,該解決方案不僅適用於
PresentationCore.dll
,而且適用於其他程序集,例如PresentationFramework.dll
,System.Xaml.dll
或System.Windows.Forms
。
您可以在應該執行解析的代碼中引用程序集。 然后,運行時將告訴您程序集的位置:
typeof([TypeKnownToBeInTheDesiredAssembly]).Assembly.CodeBase
例如,找到System.Xml.dll:
string codeBase = typeof(System.Xml.XmlDocument).Assembly.CodeBase;
UriBuilder uri = new UriBuilder(codeBase);
string path = Uri.UnescapeDataString(uri.Path);
Console.WriteLine(path);
在我的系統上:
C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Xml/v4.0_4.0.0.0__b77a5c561934e089/System.Xml.dll
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.