中引用的程序集复制规则 [英] Rules of referenced assemblies copying

查看:118
本文介绍了中引用的程序集复制规则的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

哪些规则中的解决方案并VS(MSBuild的?)按照建设?在这情况下,将复制间接引用asemblies输出文件夹,并在其中呢?

Which rules does VS (msbuild?) follow during solution build? In which cases it will copy indirectly referenced asemblies to output folder and in which not?

推荐答案

我刚刚得到了实验位,它看起来像任何间接引用的组件,该组件有一个类型的由code直接引用的另一个程序集中将被复制。如果有什么在code,也不会是。这里是我的示例场景:

I've just been a bit of experimentation, and it looks like any indirectly referenced assembly which has a type directly referenced by code in another assembly will be copied. If there's nothing in code, it won't be. Here's my sample scenario:

  • MainProgram(主程序):控制台应用程序的直接引用DirectAssembly。 code在主营:

  • MainProgram: Console application with a direct reference to DirectAssembly. Code in Main:

var foo = new DirectAssembly.SampleClass();

  • DirectAssembly:类库与直接引用IndirectAssembly。包含 SampleClass

    public class SampleClass
    {
        // Comment out this line to change the behaviour...
        IndirectAssembly.IndirectClass neverUsed = null;
    
        public SampleClass()
        {
            object x = Activator.CreateInstance("IndirectAssembly",
                                                "IndirectAssembly.IndirectClass");
    
        }
    }
    

  • IndirectAssembly:包含一个公共类 IndirectClass 与公共参数的构造函数

  • IndirectAssembly: Contains a public class IndirectClass with a public parameterless constructor

    如上所述,它的工作原理是因为IndirectAssembly被复制到MainProgram(主程序)的输出文件夹。如果您注释掉SampleClass指示线,IndirectAssembly是的没有的拷贝(尽管它仍然是一个参考)和code将无法在执行时。

    As described above, it works because IndirectAssembly is copied into the output folder of MainProgram. If you comment out the line indicated in SampleClass, IndirectAssembly is not copied (even though it's still a reference) and the code will fail at execution time.

    我并不是说这些的所有的规则,但他们至少有一个开始......

    I'm not saying these are all the rules, but they're at least a start...

    这篇关于中引用的程序集复制规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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