简体   繁体   English

VS2010:使用解决方案中另一个项目的命名空间?

[英]VS2010: Use namespace from another project within the solution?

I have two projects within a single solution in Visual Studio 2010. These projects are called Project1 and Project2.我在 Visual Studio 2010 中的一个解决方案中有两个项目。这些项目称为 Project1 和 Project2。 Within these projects, two namespaces are defined, Namespace1 and Namespace2, respectively.在这些项目中,定义了两个命名空间,分别是 Namespace1 和 Namespace2。

Inside some code within Namespace2, I'd like to use some structs, classes, etc. which I've defined in Namespace1.在 Namespace2 中的一些代码中,我想使用一些我在 Namespace1 中定义的结构、类等。 Is there any way to do this?有没有办法做到这一点?

Yes, add a reference to Project1 from Project2.是的,从 Project2 添加对 Project1 的引用。 Right-click the project, choose "Add References" then from the "Projects" tab, choose Project1.右键单击该项目,选择“添加引用”,然后从“项目”选项卡中选择 Project1。

In some cases you have to actually add the DLL of the other project to compile against, not just a reference to the project.在某些情况下,您必须实际添加其他项目的 DLL 以进行编译,而不仅仅是对项目的引用。 Make sure copy to local is enabled in that advent.确保在那个出现时启用了复制到本地。

I had this happen trying to link a console app to an MVC project.我在尝试将控制台应用程序链接到 MVC 项目时发生了这种情况。

确保在创建对它的引用之前构建项目,否则它不会显示。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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