GetReferencedAssemblies不会返回所有程序集 [英] GetReferencedAssemblies doesn't return all assemblies

查看:65
本文介绍了GetReferencedAssemblies不会返回所有程序集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Form中包含以下代码,并试图找到一种方法来加载由名为 DataObjects 的表单引用的项目程序集。使用以下代码,我只列出了六个程序集。查看表单所在项目的参考,这里有13个程序集参考。

I have the following code inside a Form, and am attempting to find a way to load a project assembly referenced by the form called DataObjects. Using the following code, I only get six assemblies listed. Looking at the references for the project the form is in, there are thirteen assembly references. What is wrong here?

private void ListReferencedAssemblies()
{
    var assemblies = Assembly.GetExecutingAssembly().GetReferencedAssemblies();
    foreach (var assembly in assemblies)
    {
        referencesListBox.Items.Add(assembly.Name);
    }
} 


推荐答案

可以您请检查程序集的清单以查看此处引用的内容?

Could you please check the assembly's manifest to see what is referenced here?

如果不使用引用的程序集,C#编译器会从清单中删除它们。因此,如果您不引用程序集B中的任何类型,或仅引用程序集B中的常量(由编译器内联),则将没有此引用。

C# compiler tends to remove referenced assemblies from the manifest if they are not used. Therefore if you don't refer to any type from assembly B or refer only to constants from assembly B (that are inlined by complier) then you will not have this references.

这篇关于GetReferencedAssemblies不会返回所有程序集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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