Without Me It Just Aweso
Without Me It Just Aweso

Reputation: 4863

C# project reference's question

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.

Upvotes: 17

Views: 8527

Answers (6)

Richard
Richard

Reputation: 109005

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 B directly (the loader will handle B referencing C).

Upvotes: 10

Sudhanshu Mishra
Sudhanshu Mishra

Reputation: 6733

There are instances where your project refers A which in turn refers B but when you build, B isn't always there in the BIN folder and you only realize this when the code is running. There is a related SO Question HERE. People have solved it in bizarre ways, but I specifically liked the solution by John Hunter. This SO thread also discusses a solution where you use build events to achieve the desired results.

Upvotes: 0

Jeff Kotula
Jeff Kotula

Reputation: 2134

Other posters are correct: you can't do it. This is, IMHO, pathetic on the part of Visual Studio. "make" handled this clean as pie 20 years ago...

Upvotes: 0

Anon
Anon

Reputation: 1

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.

Upvotes: 0

James
James

Reputation: 82096

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.

Upvotes: 3

BFree
BFree

Reputation: 103740

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.

Upvotes: 23

Related Questions