3

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?

Algorist
  • 492
  • 1
  • 5
  • 17
  • 1
    Smells like a [XY Problem](http://meta.stackexchange.com/questions/66377/what-is-the-xy-problem). Can you explain what problem you're trying to solve instead? – Sriram Sakthivel Dec 15 '14 at 10:48
  • 1
    You could load the logging assembly dynamically, but it looks like more trouble than it's worth. Are you sure the extra referenced assembly is a problem to begin with? – Frédéric Hamidi Dec 15 '14 at 10:49
  • This should help - http://stackoverflow.com/a/465509/744616 – Pranit Kothari Dec 15 '14 at 10:49
  • Yeah. I am developing a class library which I need to ship to customers. Already it contains reference may other external libraries. So if possible I just want to avoid it. Only when someone faces any problem then only I want to ship my class lib with logging capability by including logger DLL. – Algorist Dec 15 '14 at 10:52

1 Answers1

3

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).

Patrick Hofman
  • 153,850
  • 22
  • 249
  • 325