[英]C#: finding path to PresentationCore.dll (and other assemblies) in the GAC
I need to reference various assemblies in a CSharpCodeProvider
via calling ReferencedAssemblies.Add
. 我需要通过调用
ReferencedAssemblies.Add
来引用CSharpCodeProvider
各种程序集。
For some assemblies, it is sufficient to simply pass the assembly name - for example ReferencedAssemblies.Add("System.dll")
. 对于某些程序集,只需传递程序集名称就足够了-例如
ReferencedAssemblies.Add("System.dll")
。
However, PresentationCore.dll
is one of those where a full path to the assembly is required - which I may not necessarily know on the target machine. 但是,
PresentationCore.dll
是其中需要程序集完整路径的程序之一-我可能不一定在目标计算机上知道。
How can I locate the definitive path to the (latest?) respective assembly - say, in the GAC?
如何找到(最新?)各个程序集的确定路径-例如,在GAC中?
Ideally, the solution would not only work for
PresentationCore.dll
, but also other assemblies such asPresentationFramework.dll
,System.Xaml.dll
orSystem.Windows.Forms
.理想情况下,该解决方案不仅适用于
PresentationCore.dll
,而且适用于其他程序集,例如PresentationFramework.dll
,System.Xaml.dll
或System.Windows.Forms
。
You can reference the assemblies in the code that should do the resolving. 您可以在应该执行解析的代码中引用程序集。 Then the runtime will tell you the assembly location:
然后,运行时将告诉您程序集的位置:
typeof([TypeKnownToBeInTheDesiredAssembly]).Assembly.CodeBase
for example, to find the System.Xml.dll: 例如,找到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);
On my system: 在我的系统上:
C:/Windows/Microsoft.Net/assembly/GAC_MSIL/System.Xml/v4.0_4.0.0.0__b77a5c561934e089/System.Xml.dll
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.