How to share Code

Posted on 2005-03-15
Medium Priority
Last Modified: 2012-05-05
I have a .sln containing 3 separate projects.  I'd like to create a class that is shared across each of these projects.  How do I do this?  Do I have to create another project?  This is basically for my function library which in VB6 I just had in a Module that I added in to my projects (from a single path).  Thanks for the help.
Question by:deshi777
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
LVL 25

Assisted Solution

RonaldBiemans earned 500 total points
ID: 13552980
Hi deshi777, Yes create another project put your class in there, and then add a reference to this class in your other 3 projects
LVL 25

Expert Comment

ID: 13552987
You add the reference by choosing add reference in the project (in the solution explorer) and in there choose the project tab

Accepted Solution

Joe_Griffith earned 500 total points
ID: 13555402
You can also just link the file that contains the class to each project.  This effectively duplicates the code in each project but it is easy to maintain.  Here's how.

Add a file containing the class to one project.
Right click on project two and select "add an existing item".
Drill down to the class file that was added to the the first project.
Instead of clicking the OK button, click the little down arrow next to the ok button and select "Link File".
This will add a shortcut in the second project that points to the class in the first project.

LVL 25

Expert Comment

ID: 13555463
If you want to use your class in other solutions aswell, then the best way would be to create a separate solution with this class and link it the way Joe_griffith described

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses
Course of the Month10 days, 20 hours left to enroll

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question