views:

127

answers:

7

In Visual Studio 2008 I know its possible to have one solution with two (or more) projects.

Is it possible OR How is it possible for the projects to share common class files?

For example -> Project 1 has a log file handling class. Can Project 2 reference it?

My hope is to increase code re-use and avoid two copies of the same thing that need to be maintained.

The target is Winforms C# (3.5)

+7  A: 

Yes, one project can reference the other one. Simply choose Add reference > Projects and select the project to be referenced.

thelost
+3  A: 

You don't actually want the class to be in two projects. You want it to be in project A, and then add a reference from project B to project A. This will allow you to use the class in both projects.

bwarner
+1  A: 

Right click on the project that you want to use the common classes nd select "Add Reference...". In the dalog that appears, choose the "Projects" tab and select the project that contains the common classes.

Daniel Renshaw
+2  A: 

Yes, it's called "Adding a Reference."

http://msdn.microsoft.com/en-us/library/s5zwxxdw(v=VS.71).aspx

Alison R.
+6  A: 

You may want to move non-application specific common functionality to a library that is on it's own development track and reference that from both.

Christopherous 5000
A: 

You can also compile your classes you wanna use an put the to the global assembly cache

MUG4N
Throwing everything in the GAC is inviting version nightmares. This is especially fun when you make a change to a library, throw it in the GAC, and a few days later all of your apps start breaking and the other developers don't know why.
David Lively
You are completely right david. I just wanted to show this other option
MUG4N
+4  A: 

Yes, this is definitely possible. You need to add a reference to Project 1 from Project 2 (right-click Project 2 in the Solution Explorer, choose "Add Reference...", and choose Project 1 under the "Projects" tab).

Don't forget that the code for Project 1 and Project 2 is likely to be in different namespaces. You'll need to add the appropriate using statement(s).

Cameron
Thanks. +1 for the namespace reminder.
John M