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?
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: Console application with a direct reference to DirectAssembly. Code in Main:
var foo = new DirectAssembly.SampleClass();
DirectAssembly: Class library with a direct reference to IndirectAssembly. Contains 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: Contains a public class IndirectClass
with a public parameterless constructor
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...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With