Use class from different Project and Solution

RadhaKrishnaKiJaya
RadhaKrishnaKiJaya used Ask the Experts™
on
Hello Experts,
I have a Class A in Project A.  I have a Project B too.  Project B would like to use some methods from Class A.  How can I do that.

Note: I am using ASP.NET and C# in Visual Studio 2015

Thank you!
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
John TsioumprisSoftware & Systems Engineer

Commented:
In Project B you use Project A as Reference
Éric MoreauSenior .Net Consultant
Top Expert 2016

Commented:
Project A has to be of type "class library. Then in Project B, add a reference to Project A and it will be available.

Author

Commented:
Thank you John Tsioumpris for your quick reply.

I forgot to mention that, they have different solutions too.  Please let me know.

Thank you!
Exploring ASP.NET Core: Fundamentals

Learn to build web apps and services, IoT apps, and mobile backends by covering the fundamentals of ASP.NET Core and  exploring the core foundations for app libraries.

Éric MoreauSenior .Net Consultant
Top Expert 2016

Commented:
A solution is a group of projects. A project can be added to multiple solutions.

If you don't need to debug your classes of ProjectA while working in Project B, you can add a reference to the compiled DLL of project A.
Éric MoreauSenior .Net Consultant
Top Expert 2016

Commented:

Author

Commented:
Thank you Éric,
I am looking at it and update here soon.

Thank you!

Author

Commented:
Eric,
1. I need to Debug the code once the Reference is added.  How can I do that?  Is there an alternative way?

2. The Add Reference is missing from Solution Explorer when I right click it.  I can see it when I right click on Projects --> Add --> Reference.  Not sure if this is the right way.

Please let me know if I am missing anything.

Thank you!
Senior .Net Consultant
Top Expert 2016
Commented:
If you need to debug, both projects need to be in the same solution. And then you will be able add a reference to the other project loaded in the same solution as explained in https://docs.microsoft.com/en-us/visualstudio/ide/how-to-add-or-remove-references-by-using-the-reference-manager?view=vs-2019#projects-tab

Author

Commented:
Thank you Eric for your timely help.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial