I am working on various projects and I need some help but not if this is possible.
What I have are various C# projects which I want to have a C# Library that all my projects can
use, lets call this library 1.
Library 1 can make use of another library. lets call this library 2.
All projects will always use library 1 but not all projects will use library 2 within library 1.
Therefore at the moment if I create a new C# project and include library 1, I then get an error saying that library 2 isn’t available. I don’t really want to import library 2 unless the main project actually requires it. Therefore is there a way to make it so library 1 can ignore the using directive if library 2 is not available.
Hope this make sense, thanks for any help you can provide.
You should not do what you’re asking to do. If not all projects will need library 2, then you have two ways you should solve it:
I would suggest option 1. Just by asking this question, I think you have a dependency issue, and that’s what should be fixed. There might be some complex solution for hacking around this, but that’s not good for long-term maintainability.
I would also suggest googling Stable Dependencies Principle.