通过NuGet卸载并重新安装Microsoft.AspNetCore.Mvc.Core会导致找不到类型/命名空间

时间:2017-09-16 20:02:47

标签: asp.net-mvc asp.net-core visual-studio-2017

卸载并重新安装Microsoft.AspNetCore.Mvc.Core后,希望Intellisense处理一个无法看到@ Html,ViewData等的EditorTemplate视图,我收到了大量的错误信息。先前有过:

The type or namespace name 'Controller' could not be found (are you missing a using directive or an assembly reference?)
The type or namespace name 'ValidateAntiForgeryToken' could not be found (are you missing a using directive or an assembly reference?)
The type or namespace name 'ValidateAntiForgeryTokenAttribute' could not be found (are you missing a using directive or an assembly reference?)

等等。如何将其恢复到正常运行的位置?我尝试过构建/重建/清洁解决方案和项目无济于事。

我在Dependencies的NuGet部分看到的内容(无标记):

Microsoft.ApplicationInsights.AspNetCore (2.0.0)
Microsoft.AspNetCore (1.1.2)
Microsoft.AspNetCore.Authentication.Cookies (1.1.2)
Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore (1.1.2)
Microsoft.AspNetCore.Identity.EntityFrameworkCore (1.1.2)
Microsoft.AspNetCore.Mvc.Core (1.1.3)
Microsoft.AspNetCore.StaticFiles (1.1.2)
Microsoft.EntityFrameworkCore.Design (1.1.2)
Microsoft.EntityFrameworkCore.SqlServer (1.1.2)
Microsoft.EntityFrameworkCore.SqlServer.Design (1.1.2)
Microsoft.EntityFrameworkCore.Tools (1.1.1)
Microsoft.Extensions.Configuration.UserSecrets (1.1.2)
Microsoft.Extensions.Extensions.Logging.Debug (1.1.2)
Microsoft.VisualStudio.Web.BrowserLink (1.1.2)
Microsoft.VisualStudio.Web.CodeGeneration.Design (1.1.1)

1 个答案:

答案 0 :(得分:1)

Microsoft.AspNetCore.Mvc.Controller类位于Microsoft.AspNetCore.Mvc.ViewFeatures程序集中,该程序集是 Microsoft.AspNetCore.Mvc 程序包的依赖项。只需安装 Microsoft.AspNetCore.Mvc ,而不是当前的 Microsoft.AspNetCore.Mvc.Core ,它将解决您的问题。