找不到命名空间(ASP.NET MVC 3)
我目前正在 Visual Studio 中开发 ASP.NET MVC3 项目。我设置了一个包含两个单独项目的解决方案。我是 ASP.NET 的新手,我认为我缺少一些基本的东西,因为我无法在尝试引用的类所在的项目之外引用类。
只是澄清一下:
我有包含 classA 的 projectA。 我有包含 classB 的projectB。
我将其输入到 classA:
using Solution.projectB.classB
我收到一条错误,指出 projectB 不存在。
I am currently working on an ASP.NET MVC3 project in Visual Studio. I have a solution set up that contains two seperate projects. I'm new to ASP.NET and I think I'm missing something basic as I cant reference classes out-with the Project that the class trying to reference is located in.
Just to clarify:
I have projectA that contains classA.
I have projectB that contains classB.
I type this into classA:
using Solution.projectB.classB
I get an error saying that projectB does not exist.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
项目 A 需要对项目 B 进行项目引用,即右键单击项目 A,选择“添加引用”,选择“项目”,然后选择“项目 B”。
Project A needs a Project Reference to Project B, i.e. right-click on Project A, select Add Reference, select Projects, and select Project B.
您需要将项目 A 中的引用添加到项目 B 中,反之亦然。
You need to add the reference from project A into project B or visa versa.
您应该引用名称空间而不是直接引用类。
尝试将您的
using
更改为:You should reference to the namespace and not directly to the class.
Try changing your
using
to:.NET 可以查看同一项目中的命名空间。默认情况下,它无法看到同一解决方案中不同项目的命名空间。您需要添加从顶级项目“A”到依赖项目“B”的引用。
如何:向 Visual Studio Web 项目添加项目引用
添加后参考,让 Visual Studio 来完成繁重的工作。类型
classB instanceOfB = new classB();
(假设有默认构造函数)使用鼠标单击 classB。按快捷键 CTRL + .。这将打开一个下拉菜单,让您可以选择自动导入名称空间。
Visual Studio 将使用语法着色来让您知道该过程已成功。或者,使用 CTRL + SHIFT + B 编译项目。
.NET can see namespaces across the same project. By default, it cannot see namespaces across different projects in the same solution. You need to add a reference from the top level project "A" to the dependent project "B".
How to: Add a Project Reference to a Visual Studio Web Project
After adding the reference, let Visual Studio do the heavy lifting. Type
classB instanceOfB = new classB();
(assuming there's a default constructor)Use your mouse to click on classB. Hit the shortcut key CTRL + .. This will open up a drop down giving you the option to automatically import the namespace.
Visual Studio will use syntax coloring to let you know that the process was successful. Alternatively, use CTRL + SHIFT + B to compile the project.