views:

324

answers:

4

I have a c# solution and its composed of numerous projects.

I have a project that is my baseassemblies that holds all common information that other projects use. All of the other projects have references to baseassemblies.

I added a dll reference in my baseassemblies however all of the other projects cant see it.

How can I make it so that the other projects can see the DLL that baseassemblies is referencing? I dont want to have to add the DLL to all of the projects since that defeats the purpose of my baseassemblies project.

+10  A: 

The correct approach is for your other assemblies NOT to need a reference to that other DLL. The way to correctly do that, is to not have your base assemblies expose any of the types that are within that DLL. Wrap all the functionality that you need in the base assemblies, and make sure that whoever consumes your base assemblies, needs NO knowledge of the underlying dll's base assemblies is using. Otherwise, each project that will reference your base assemblies, if they need to use something that's contained in that dll, they'll have to reference it.

BFree
+1 you beat me to it. I agree 100%
klausbyskov
+3  A: 

There are no transitive references in .NET. If an assembly needs to reference another it must do so directly, it cannot "inherit" that reference from another reference.

Note, a project only needs to reference assemblies it directly uses types from. If A uses B, and B uses C, but A does not directly use C, then A only needs to reference A directly (the loader will handle B referencing C).

Richard
+2  A: 

In short you can't do it. You need to add a reference to the DLL containing the code you are trying to use otherwise it won't be able to see it.

My suggestion would be to create a layer in your 'BaseAssemblies' project which you can access from your application which essentially creates a tiered architecture.

example

Application Layer - Uses IDataClass
Business Logic Layer - Defines IDataClass
Data Access Layer - MyRawDataClass (implements IDataClass)

From the example, the application layer only needs a reference to the BAL to be able to interact with the DAL.

James
A: 

You can have your BaseAssemblies export Interfaces that have to be implemented by your "other" dll. Additionally, your BaseAssemblies need some "class factory" functionality for those classes.

Anon