简体   繁体   English

如何获取引用的程序集的物理路径

[英]How to get the physical path of the referenced assemblies

I have one main assembly, this assembly has referenced some more assembly. 我有一个主组件,这个组件引用了一些更多的组件。 I am able to get those referenced assmbly names. 我能够获得那些引用的汇编名称。 But, i am unable to retrive the physical path of those referenced assemblies. 但是,我无法检索那些引用程序集的物理路径。 Any one can help me on this? 任何人都可以帮助我吗?

I am using the following code. 我使用以下代码。

string path = Path.GetFullPath(txtFileName.Text);
Assembly a = Assembly.LoadFrom(path);

    foreach (AssemblyName an in a.GetReferencedAssemblies())  {
    Assembly asm = Assembly.Load(an);                
    MessageBox.Show(an.FullName.ToString() + "Location : " + asm.CodeBase.ToString());
    }

It gives me the path of the system assembly "mscorlib". 它给了我系统组件“mscorlib”的路径。 But when it try to retrive the user created assembly, it says "The system cannot find the file specified". 但是当它尝试检索用户创建的程序集时,它会显示“系统找不到指定的文件”。

Perhaps like this: 也许是这样的:

string path = System.Reflection.Assembly.GetAssembly(typeof(asm)).Location;

string dir = Path.GetDirectoryName( path);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM