找到像CLR那样的托管程序集 [英] Find managed Assembly like CLR does

查看:76
本文介绍了找到像CLR那样的托管程序集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hey Guys,



i希望编写一个简单的应用程序,显示来自(托管)C#DLL或应用程序的dependdencys。



目前我在C#中尝试这个,但是(非托管)VC ++中的解决方案是优先的。

在C#中我这样做:

Hey Guys,

i want to write a simple Application that show the depedencys from a (Managed)C# DLL or Application.

Currently i'm trying this in C# but a solution in (unmanaged)VC++ is preffered.
In C# i'm doing this with:

Assembly MyAssembly = Assembly.LoadFrom( sPathToMyAssembly );
AssemblyName[] MyAssemblyNames = MyAssembly.GetReferencedAssemblies();
StringBuilder sResult = new StringBuilder();
foreach( AssemblyName MyAssemblyName in MyAssemblyNames )
{
    sResult.Append( MyAssemblyName.Name + "|" );
}
if( sResult.Length > 1 )
    sResult.Remove( sResult.Length - 1, 1 );



所以我得到一个包含所有引用汇编的字符串。



这个问题solutino是,我没有获得路径或全名。

我只能获得


So i get a string with all referenced assemblys.

The problem with this solutino is, that i'm not getting a path or a full name.
I'm only get

System.Windows.Forms|mscorlib|System|System.Data|System.Drawing



结果。



我想得到类似 C:\ Path \To \This \Assembly.DLL

C:\ Path\To\This\Other\Assembly.EXE



非常感谢你的帮助!!!!


as result.

I want to get something like C:\Path\To\This\Assembly.DLL
or C:\Path\To\This\Other\Assembly.EXE

Thanks so much for your help!!!!

推荐答案

我不明白你怎么能错过这个属性: http://msdn.microsoft.com/en-us/library/system.reflection.assembly.location%28v=vs.110%29.aspx [ ^ ]。



但是,您应该了解此位置对于未放入GAC的程序集非常有用。使用GAC中的程序集,无论如何都会获得正确的位置,只能从这些位置加载它们是不正确的(除非这仅用于研究)。这些组件确实由它们的强名称标识,并且应该这样引用。



参见:

http://en.wikipedia.org/wiki/Global_Assembly_Cache [ ^ ],

http://en.wikipedia.org/wiki/Strong_key [ ^ ]。



-SA
I don't understand how could you miss this property: http://msdn.microsoft.com/en-us/library/system.reflection.assembly.location%28v=vs.110%29.aspx[^].

However, you should understand that this location is useful for assemblies which are not put in GAC. With assemblies in GAC, you will get correct locations anyway, only loading them from these locations won't be correct (unless this is just for research). Such assemblies are really identified by their strong names and should be referenced as such.

See also:
http://en.wikipedia.org/wiki/Global_Assembly_Cache[^],
http://en.wikipedia.org/wiki/Strong_key[^].

—SA


这篇关于找到像CLR那样的托管程序集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆