Algorist
Algorist

Reputation: 492

Refer .NET assembly based on compiler switch

I need to add reference to another assembly in my c# project based on some compiler switch like #ifdirective. For example I want to add reference to logger DLL in my project only when I need it. Is this possible?

Upvotes: 3

Views: 68

Answers (1)

Patrick Hofman
Patrick Hofman

Reputation: 157038

As far as I know, a referenced assembly that isn't used AT ALL, isn't a problem. You can even keep it as reference.

As long as your code doesn't trigger the assembly to be loaded, there is no need to have that file available.

I would suggest though to check whether you really need this, and if you can workaround this by creating interfaces and dynamically load the assembly (using Assembly.LoadFrom).

Upvotes: 3

Related Questions