.NET Web 应用程序上的自定义命名空间
所以我编写了一些自定义类并将它们全部放在一个命名空间中,称之为“Sphere”。
在我的 aspx.cs 代码隐藏文件中,我有“using Sphere;” 书面。 我知道这是有效的,因为它始终有效,直到我将此项目复制到新文件夹为止。 此外,即使当我单击“在网络浏览器中查看”时,一切都正常。
简而言之,Visual Studio 08 无法识别命名空间,因此我无法在没有错误的情况下进行构建,因此无法进行调试。 谢谢您的帮助!
编辑: 我的命名空间位于 .cs 文件中的 App_Code 文件夹中
So I wrote some custom classes and put them all in a namespace, call it "Sphere".
On my aspx.cs codebehind file, I have "using Sphere;" written. I know that this works because it's always worked until I copied this project to a new folder. Also, even when I click "view in web browser" everything works perfectly.
Simply, Visual Studio 08 is not recognizing the namespace and so I cannot build without an error and consequently cannot debug. Thanks for the help!
edit:
I have my namespace in my App_Code folder in a .cs file
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
您的自定义类位于单独的项目中吗? 如果是这样,您可能需要添加对该项目的引用。 如果您已将项目复制到新文件夹,则 VS2008 中 Sphere DLL/项目的路径可能会损坏。
Are your custom classes in a separate project? If so, you might need to add a reference to that project. If you have copied the project to a new folder, the path to your Sphere DLL/project in VS2008 might be broken.
我实际上刚刚弄清楚:
我的 .cs 文件被设置为“构建操作:内容”而不是“编译”。 我右键单击+属性我的所有文件并更改了构建操作,现在一切正常了!
I actually just figured it out:
My .cs files were set to "build action: content" rather than "compile." I right-clicked + properties all my files and changed the build action, and now it all works!
听起来像是缺少参考。
在您的新项目中,您是否有对定义实际 Sphere 命名空间的项目的引用?
Sounds like missing reference.
In your new project, do you have a reference to the project that defines the actual Sphere namespace?
检查你的参考资料。 在您移动应用程序的文件夹后,VS 可能不再找到它们。
Check your references. It's possible VS is no longer finding them after you moved your application's folder.
听起来好像当您移动文件时引用已损坏。 如果球体类位于单独的 dll 中,请尝试删除并重新添加引用。 如果它只是在 .de 文件中,请确保项目中的文件仍在相对路径中。
It sounds like when you moved the files the references were broken. If the sphere classes are in a seperate dll try deleting and re-adding the reference. If it is just in a .de file be sure that filein the project is still in the relative path.
可能你遇到了这个错误:
并且该类型不在程序集中的原因是 App_Code 文件夹是特定文件夹网站项目。 这些文件在部署到服务器上时在运行时编译,而不是在构建项目时编译。
在Web应用程序项目中,每个文件都有Build Action属性。 默认情况下,类文件的值为“编译”。 但是,如果该类是在 App_Code 文件中创建的,它将获取值 Content。 并且在作为应用程序运行时不会被编译。
最后,App_Code 文件夹不适合在 Web 应用程序中使用。 或者,正如您所想,您可以手动将“构建操作”更改为“编译”。
我通过搜索这些链接找到了答案:
Probably you got this error:
And the reason the type was not in the assembly is that App_Code folder is specific folder for Web Site Projects. These files get compiled at runtime when they are deployed on server and not when you are building the project.
In Web Application Project every file has Build Action property. By default the classes files have value of Compile. But if the class is created in App_Code file it gets value Content. and does not get compiled when running as Application.
A the end the App_Code folder is not meant to be used in Web Application. Or as you figured it out you can manually change the Build Action to Compile.
I found the answer by searching these links: