pencilCake
pencilCake

Reputation: 53223

What is the impact of adding a reference on compiled code?

When I add a reference to a .dll file, what changes in the compiled output of a project?

(Just imagine I have added a reference and rebuild.)

Upvotes: 0

Views: 61

Answers (2)

Oded
Oded

Reputation: 498942

The manifest will record the reference to the .dll file - if it is not used, the compiler will drop the reference in the compiled manifest. So, in this case, no impact.

If you have defined any extension methods in this library that provide better matches for your existing (unmodified) code, this constitutes a use of this library and the extension methods will be used.

If this is not a .NET assembly, but a com/com+ dll, a wrapper will be generated as well.

Nothing else should change in regards to the MSIL portion of the compiled assembly.

Upvotes: 2

Marc Gravell
Marc Gravell

Reputation: 1062600

If it is just a reference (and assuming the dll is an assembly) - none whatsoever; unused references are silently dropped by the compiler and in your scenario you didn't add any code that uses the assembly (i.e. some code that uses types from the new dll). Note I'm making the slight assumption here that there were no extension methods in the new dll (in namespaces that were already in use) that provided better matches for existing extension method uses.

If you have marked the reference to Copy Local = True, then in your output directory you'll get the extra dll (but internally your assembly will not formally reference it - that reference is still dropped if your code doesn't touch the assembly).

Upvotes: 2

Related Questions