Joshua Beckers
Joshua Beckers

Reputation: 907

How to use class from other project in visual studio C#

I have a Xamarin.Forms project and a C# console app project. I want to use one class from the console app in my Xamarin.Forms project.

I added the console app project to the solutions explorer of the Xamarin.Forms project.

Unfortunately, I can't figure out how to use the class from the console app in one of the Xamarin files.

I always get the error message:

The name 'MyClass' does not exist in the current context.

I tried to press alt+enter to show potential fixes but it does not offer me the option of importing/using the class.

I also wrote manual using directives in various forms but it still does not seem to make the class accessible.

The only way I was able to use the class was by adding the class directly to the Xamarin project by adding it with add->existing item. The problem with this is that it imports a copy of the class. Since I'm still working on the class within the other project the added class is fast outdated and I have to manually copy its contents over.

How can I use a class from an external project without making a copy of the file?

Upvotes: 0

Views: 496

Answers (2)

Leo Zhu
Leo Zhu

Reputation: 15021

Try to add a reference to the second project in your first project. To do this, right-click on your project, select Add Reference then select the project in your solution. Once your main project references the second project, then you can access its public types.

Upvotes: 0

Rajanikant Hawaldar
Rajanikant Hawaldar

Reputation: 314

Instead of access class from console app(its exe) try creating new reusable library add that class and use in both projects also you can write wrapper class in both projects

Upvotes: 1

Related Questions