发布ASP .NET MVC项目时"无法找到类型或命名空间名称"

rjg*_*234 1 c# asp.net asp.net-mvc compiler-errors visual-studio-2010

我是C#ASP .NET MVC的新手,所以我不太确定很多事情.但是我在我的新公司继承了这个项目,我只是想构建我在这里开始时接管的计算机上存储的文件.我很确定没有人触及这些文件,因为最后一个人离开了,所以我认为代码应该没有问题,因为该网站现在正在运行并正常工作.

但是当我尝试将这些文件发布到临时站点(出于测试目的)时,我得到了一堆相同的错误(取出了错误中给出的完整路径),并且项目无法发布.

    Error   77  The type or namespace name 'Controller' could not be found (are you missing a using directive or an assembly reference?)    \Controllers\AccountController.cs   15  38  Project
Error   99  The type or namespace name 'HttpGetAttribute' could not be found (are you missing a using directive or an assembly reference?)  \Controllers\AccountController.cs   17  10  Project
Error   100 The type or namespace name 'HttpGet' could not be found (are you missing a using directive or an assembly reference?)   \Controllers\AccountController.cs   17  10  Project
Error   115 The type or namespace name 'ActionResult' could not be found (are you missing a using directive or an assembly reference?)  \Controllers\AccountController.cs   18  16  Project
Error   182 The type or namespace name 'HttpPostAttribute' could not be found (are you missing a using directive or an assembly reference?) \Controllers\AccountController.cs   40  10  Project
Error   183 The type or namespace name 'HttpPost' could not be found (are you missing a using directive or an assembly reference?)  \Controllers\AccountController.cs   40  10  Project
Error   186 The type or namespace name 'ActionResult' could not be found (are you missing a using directive or an assembly reference?)  \Controllers\AccountController.cs   41  16  Project
Error   257 The type or namespace name 'HttpGetAttribute' could not be found (are you missing a using directive or an assembly reference?)  \Controllers\AccountController.cs   78  10  Project
Error   258 The type or namespace name 'HttpGet' could not be found (are you missing a using directive or an assembly reference?)   \Controllers\AccountController.cs   78  10  Project
Error   265 The type or namespace name 'ActionResult' could not be found (are you missing a using directive or an assembly reference?)  \Controllers\AccountController.cs   79  16  Project
Error   284 The type or namespace name 'HttpPostAttribute' could not be found (are you missing a using directive or an assembly reference?) \Controllers\AccountController.cs   89  10  Project
Error   285 The type or namespace name 'HttpPost' could not be found (are you missing a using directive or an assembly reference?)  \Controllers\AccountController.cs   89  10  Project
Error   291 The type or namespace name 'ActionResult' could not be found (are you missing a using directive or an assembly reference?)  \Controllers\AccountController.cs   90  16  Project
Error   332 The type or namespace name 'AuthorizeAttribute' could not be found (are you missing a using directive or an assembly reference?)    \Controllers\AccountController.cs   112 10  Project
Error   333 The type or namespace name 'Authorize' could not be found (are you missing a using directive or an assembly reference?) \Controllers\AccountController.cs   112 10  Project
Error   335 The type or namespace name 'ActionResult' could not be found (are you missing a using directive or an assembly reference?)  \Controllers\AccountController.cs   113 16  Project
Error   343 The type or namespace name 'AuthorizeAttribute' could not be found (are you missing a using directive or an assembly reference?)    \Controllers\AccountController.cs   121 10  Project
Error   344 The type or namespace name 'Authorize' could not be found (are you missing a using directive or an assembly reference?) \Controllers\AccountController.cs   121 10  Project
Error   345 The type or namespace name 'ActionResult' could not be found (are you missing a using directive or an assembly reference?)  \Controllers\AccountController.cs   122 16  Project
Error   363 The type or namespace name 'HttpGetAttribute' could not be found (are you missing a using directive or an assembly reference?)  \Controllers\AccountController.cs   150 10  Project
Error   364 The type or namespace name 'HttpGet' could not be found (are you missing a using directive or an assembly reference?)   \Controllers\AccountController.cs   150 10  Project
Error   365 The type or namespace name 'AuthorizeAttribute' could not be found (are you missing a using directive or an assembly reference?)    \Controllers\AccountController.cs   151 10  Project
Error   366 The type or namespace name 'Authorize' could not be found (are you missing a using directive or an assembly reference?) \Controllers\AccountController.cs   151 10  Project
Error   367 The type or namespace name 'ActionResult' could not be found (are you missing a using directive or an assembly reference?)  \Controllers\AccountController.cs   152 16  Project
Error   377 The type or namespace name 'HttpGetAttribute' could not be found (are you missing a using directive or an assembly reference?)  \Controllers\AccountController.cs   162 10  Project
Error   378 The type or namespace name 'HttpGet' could not be found (are you missing a using directive or an assembly reference?)   \Controllers\AccountController.cs   162 10  Project
Error   379 The type or namespace name 'AuthorizeAttribute' could not be found (are you missing a using directive or an assembly reference?)    \Controllers\AccountController.cs   163 10  Project
Error   380 The type or namespace name 'Authorize' could not be found (are you missing a using directive or an assembly reference?) \Controllers\AccountController.cs   163 10  Project
Error   384 The type or namespace name 'ActionNameAttribute' could not be found (are you missing a using directive or an assembly reference?)   \Controllers\AccountController.cs   164 10  Project
Error   385 The type or namespace name 'ActionName' could not be found (are you missing a using directive or an assembly reference?)    \Controllers\AccountController.cs   164 10  Project
Run Code Online (Sandbox Code Playgroud)

对于项目中的大量文件,存在更多相同类型的错误.错误显示的方式让我相信这是一个简单的一次性修复,因为它们几乎都是相同的错误.

任何人都知道如何解决这些错误,以便我可以成功构建这个项目?

Ins*_*rel 7

您需要确保您的项目引用了所有必需的命名空间.例如,HttpGetAttribute该列表中的所有其他实际属于System.Web.Mvc.

如果在VS中打开该项目的引用"文件夹",您可能会在某些引用旁边看到警告标志.删除它们并重新添加它们.

要重新添加引用,请先删除它,然后右键单击References文件夹,再单击Add Reference.单击左侧的Assembles树视图项,然后在右侧的搜索框中键入System.Web.Mvc,它将显示该DLL的版本列表.

为了将来参考,每当你看到这样的东西时,解决它的最好方法是只搜索无法找到的类的名称,然后搜索"MSDN",在你的情况下搜索"HttpGetAttribute msdn".这将告诉您需要包含哪个参考.

  • 在这种情况下,你想删除`System.Web.WebPages`并重新添加版本`2.0.0.0` DLL,或者你可以尝试重新添加较低版本的`System.Web.Mvc`,看看是否其中任何一个都完全消除了所有问题.我可能会首先尝试,因为更改`WebPages` DLL可能会引发更多问题. (2认同)
  • 谢谢!有效.我不得不添加`System.Web.Mvc 3.0.0.1`来使它工作.感谢帮助/耐心. (2认同)