繁体   English   中英

在 ASP.NET Core 2.1 MVC 中使用 Entity Framework Core 搭建新控制器的问题

[英]Problem scaffolding new controller using Entity Framework Core in ASP.NET Core 2.1 MVC

两天前我在做一个项目时遇到了一个问题。

当我尝试通过将鼠标悬停在View()方法上然后单击“添加视图”来创建新控制器或视图时,VS 不会生成任何内容也没有错误消息,但这些行:

Finding the generator 'controller'...
Running the generator 'controller'...
Attempting to compile the application in memory.
   at Microsoft.VisualStudio.Web.CodeGeneration.ActionInvoker.<BuildCommandLine>b__6_0()
   at Microsoft.Extensions.CommandLineUtils.CommandLineApplication.Execute(String[] args)
   at Microsoft.VisualStudio.Web.CodeGeneration.ActionInvoker.Execute(String[] args)
   at Microsoft.VisualStudio.Web.CodeGeneration.CodeGenCommand.Execute(String[] args)

我试图将 VS 更新到最新版本,现在是 16.4.3 社区版,但没有运气。

试图从 NuGet 重新安装Microsoft.VisualStudio.Web.CodeGeneration但再次没有运气。

试图删除 .vs 文件夹,但再次失败。

可能是什么问题呢? 在此之前它可以正常工作,但脚手架停止工作。

谢谢

事实证明,它具有某种 c# 语言语法。 在 GitHub 上阅读此问题帮助我找到了解决方法。

帮助我解决问题的是这条评论

通过添加这个包:

Microsoft.CodeAnalysis.CSharp.Workspaces

在评论中,包版本是 3.3.1,但我安装了 3.4.0,它的工作原理很吸引人。

我遇到过同样的问题。 Ubuntu 18.04.5 LTS,Rider EAP 2020.3。 C# 9,dotnet-aspnet-codegenerator 版本“5.0.1”,dotnet 5.0.102。

Finding the generator 'controller'...
Running the generator 'controller'...
Attempting to compile the application in memory.
Attempting to figure out the EntityFramework metadata for the model and DbContext: 'Person'
A file matching the name MvcControllerWithContext.cshtml was not found within any of the folders: 
   at Microsoft.VisualStudio.Web.CodeGeneration.ActionInvoker.<BuildCommandLine>b__6_0()
   at Microsoft.Extensions.CommandLineUtils.CommandLineApplication.Execute(String[] args)
   at Microsoft.VisualStudio.Web.CodeGeneration.ActionInvoker.Execute(String[] args)
   at Microsoft.VisualStudio.Web.CodeGeneration.CodeGenCommand.Execute(String[] args)

在绝望模式下开始尝试一切并遇到这个问题,它与我的配置一起工作。

在我的情况下,我修复了它,将项目的目标更改为“Net 5.0”(我知道这并不总是可行的),然后通过(工具/管理 Nuget 包)将这些包更新到最新版本(此时是5.0.9):

  • Microsoft.EntityFrameworkCore
  • Microsoft.EntityFrameworkCore.SqlServer
  • Microsoft.EntityFrameworkCore.Tools

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM