How are classes shared between projects in the same solution?
I'm totally new to the Microsoft dev scene so please go easy :) Currently, I have a solution that contains two projects (ASP.net websites, FWIW). If I create a class in Project1, how do I expose it to Project2? Is it automatically available to Project2 because they are in the same solution? Or do I need to do somethi开发者_如何学Gong special to make the connection?
you need to Add Reference of Class to the project
Like this:
Then Go to Projects Tab (if your project is in Same Soln) .Select the class library need to refer and click ok.
When you expand your Reference you can see the class1.dll like this
Hope this may help you :)
Go to the properties of Project2
, and add Project1
as a "Project Reference".
Then your class will be available via Project1.ClassName
You can then use the Imports Project1
statement to shorten the reference, and just reference ClassName
Add a project reference. Go to solution explorer and right click on Project 2's 'References' node. Select 'Add refrence'. From the 'Projects' tab select Project 1. That's it. Now you can use classes from Project 1 in Project 2.
You need to add a reference to the project (context menu on the project) and add Imports
statements in your class files to use objects from the other project.
Normally you would just create a reference from Project 1 to Project 2, but as they are both ASP.NET websites i don't know if that would be possible (i've never tried that particular combo).
What you can do instead if that fails is share the actual class files between the two projects - in the Solution Explorer right click, Add existing file, then browse to the file containing the wanted class in project 2, and then just before you click Add, click the little down arrow on the button and select Add as link.
精彩评论