簡體   English   中英

C#:在GAC中找到PresentationCore.dll(和其他程序集)的路徑

[英]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.dllSystem.Xaml.dllSystem.Windows.Forms

未產生預期結果的來源:

  • 該解決方案將涉及對特定路徑進行硬編碼,但是該解決方案應該是動態的
  • 實施此Windows API可能有效; 但我不知道如何-甚至是否可以解決上述問題
  • 這個 C ++問題是指在哪里找到GAC,而不是如何獲取實際文件路徑

您可以在應該執行解析的代碼中引用程序集。 然后,運行時將告訴您程序集的位置:

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM