Zann Anderson
Zann Anderson

Reputation: 4907

Project reference vs. DLL Reference - Which is better?

I know there are other questions regarding this subject, and I've looked at this question, but I'd like to see a little bit more discussion and information on both sides of this - is it a better practice to add a project to a solution and reference the project, or to add a reference to the .dll?

Upvotes: 48

Views: 30684

Answers (5)

Hans Passant
Hans Passant

Reputation: 941465

It's not much of a choice. If you have a solution with both projects then use a project reference. If your solution doesn't have the project then you have to use an assembly reference.

So the real question should probably be: do I create a solution with both projects? Yes, as long as the project is still in the debug stage and liable to require bug fixes.

Upvotes: 38

Franz
Franz

Reputation: 87

Summary - Project Reference by Project vs by DLL

Reference by project

  • code is visible
  • finds all references e.g. on a class (because code is visible)
  • better for testing (over all)
  • better for code redesign (impact)

Reference by DLL

  • code is hidden
  • separation between e.g. framework and project (for deliver of framework)
  • quicker compilation (because DLL is already compiled)

Upvotes: 6

ChrisF
ChrisF

Reputation: 137148

If you only have the dll then you're stuck with a dll reference (obviously).

If you have the source then it's usually better to use a project reference. There might be cases where you have a utility library that's never going to change, but if there's the slightest chance of you needing a bug fix then having a project reference is going to make debugging a lot easier.

Upvotes: 24

Pradish
Pradish

Reputation: 1

Relative to your project architecture, you should always stick to projects within your problem domain. You should be using the GAC, if that is applicable to your environment.

Upvotes: -3

Taylor Leese
Taylor Leese

Reputation: 52310

Well, project references are helpful when you are building and testing in both debug and release mode. If you directly add a DLL then you are locked into whatever that particular DLL was built as. The project reference allows this to be a build time decision.

Upvotes: 3

Related Questions