我需要通过调用CSharpCodeProvider
来引用ReferencedAssemblies.Add
中的各种程序集。
对于某些程序集,只需传递程序集名称就足够了 - 例如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