John M
John M

Reputation: 14668

Visual Studio 2008 - Is it possible for two projects to share common classes?

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)

Upvotes: 1

Views: 333

Answers (7)

Cameron
Cameron

Reputation: 98746

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).

Upvotes: 4

MUG4N
MUG4N

Reputation: 19717

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

Upvotes: 0

Christoph
Christoph

Reputation: 4401

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.

Upvotes: 6

Alison R.
Alison R.

Reputation: 4294

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

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

Upvotes: 2

Daniel Renshaw
Daniel Renshaw

Reputation: 34177

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.

Upvotes: 1

bwarner
bwarner

Reputation: 872

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.

Upvotes: 2

thelost
thelost

Reputation: 6694

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

Upvotes: 6

Related Questions