发布ASP.NET MVC项目时“找不到类型或命名空间名称”

lfapxunr  于 2023-03-20  发布在  .NET
关注(0)|答案(4)|浏览(387)

我是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

项目中的很多文件都有很多相同类型的错误。错误显示的方式让我相信这是一个简单的一次性修复,因为它们几乎都是相同的错误。
有人知道如何修复这些错误,以便我可以成功地生成此项目吗?

vvppvyoh

vvppvyoh1#

您需要确保您的项目引用了所有必需的名称空间,例如,HttpGetAttribute和列表中的所有其他名称空间实际上都属于System.Web.Mvc
如果你在VS中打开该项目的引用“文件夹”,你可能会在一些引用旁边看到警告标志。删除它们,然后重新添加。
要重新添加引用,首先删除它,然后右键单击References文件夹,然后单击Add Reference。单击左边的Assembles树视图项,然后在右边的搜索框中键入System.Web.Mvc,它会弹出该DLL的版本列表。
对于将来的参考,当你看到类似的问题时,解决它的最好方法是搜索后面跟有'MSDN'的类的名称,在你的例子中,你会搜索'HttpGetAttribute msdn '。这会告诉你需要包含哪个引用。

pbwdgjma

pbwdgjma2#

首先确保基本项目(没有对其他项目的任何引用)生成正常。如果没有,请检查项目树中的References文件夹。如果任何图标有警告,则对库的引用无效。
然后从基本项目转到引用基本项目的项目,并继续进行,直到整个解决方案再次构建完毕。

68bkxrlz

68bkxrlz3#

此问题很可能是由于未还原Nuget包造成的。如果您的团队未将Nuget包签入源代码管理,则需要在解决方案资源管理器中右键单击该解决方案并选择“启用Nuget包还原”,然后重新生成该解决方案。

raogr8fs

raogr8fs4#

我遇到了这个问题。我尝试了上面所有的答案。最终修复它的事情是关闭并重新打开解决方案。

相关问题