问题
I have two projects within a single solution in Visual Studio 2010. These projects are called Project1 and Project2. Within these projects, two namespaces are defined, Namespace1 and Namespace2, respectively.
Inside some code within Namespace2, I'd like to use some structs, classes, etc. which I've defined in Namespace1. Is there any way to do this?
回答1:
Yes, add a reference to Project1 from Project2. Right-click the project, choose "Add References" then from the "Projects" tab, choose Project1.
回答2:
In some cases you have to actually add the DLL of the other project to compile against, not just a reference to the project. Make sure copy to local is enabled in that advent.
I had this happen trying to link a console app to an MVC project.
来源:https://stackoverflow.com/questions/4416879/vs2010-use-namespace-from-another-project-within-the-solution