views:

55

answers:

1

Using Visual Studio 2008:

Within the Solution there is a main project (Project1), within the same solution there are other projects (these projects are Excel 2007 Workbook templates). These other projects need to reference classes and objects within Project1, and Project1 needs to be able to access the Workbook projects.

What I currently have now is the other projects are set to be dependent upon Project1 and a reference is added to the other projects for Project1.

Is this the correct way to do what I am trying to accomplish or is there another way?

+6  A: 

You cannot have two projects depend on each other (this is entirely logical; which project should be built first?). You should move the parts in Project1 that is needed both by Project1 and the Workbook projects into a separate project, that can be referenced both by Project1 and the Workbook projects.


Update
There are several different ways of handling this situation, and without knowing the details of your application I can't give any specific solution. But one way is to use dependency injection. Instead of having the Workbook project have a hard-wired dependency on the code in Project1, you can extract an interface for this functionality. This interface is placed in another project that can be referenced both by Project1 and the Workbook project.

Then I assume that Project1 will create instances of types in the Workbook project. This means that you should alter the constructors of these types to have a parameter if this interface type. Project1 will contain an implementation of the interface that it will pass to the Workbook project types when creating them.

That way the Workbook project code can use code from Project1 without having a reference to it.

Fredrik Mörk
+1, yeah create a project called "Common" to put those shared dependencies in.
JohnB
I do understand that you cant have two project reference each other that would be a recursive nightmare. Then how would I reference the Excel workbook template projects from the Project1? So instead of the Excel workbook template projects depending on Project1, have both Project1 and the Excel workbook projects depend on CommonProject, and then have Project1 depend on all of the Excel workbook projects?
mattgcon
@mattgcon: see my updated answer.
Fredrik Mörk