简体   繁体   中英

Handling common classes in multiple projects in a single solution

I currently have two projects say project A and project B in my solution. Now both projects A and B are using similar classes and a copy of each class is found in each project. I wanted to know if there is a better way to accomplish this task. I want to have a single class somewhere and have both projects access common classes from there. What is the recommneded way to do this.

  1. Create a third project C in the same solution.
  2. Add your shared classes to C.
  3. Reference C in the projects A and B. (to do so : in the Solution Explorer , right click on References in project A and B, click Add Reference , click on tab Projects , then select Project C, click OK )
  4. Don't forget to add the correct using namespace to use the class in the project A and B.

Or just let your shared classes in project A, or B and add reference to this project in the other project (It depends on the content but doing this way will create a kind of assymetry between the projects A and B).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM