[英]Problem scaffolding new controller using Entity Framework Core in ASP.NET Core 2.1 MVC
I got a problem two days ago while working on a project.两天前我在做一个项目时遇到了一个问题。
When I try to create a new controller or a view by hovering over the View()
method and then clicking "Add View", VS generates nothing and no error message but these lines :当我尝试通过将鼠标悬停在
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)
I tried to update VS to latest version which is now 16.4.3 Community edition but with no luck.我试图将 VS 更新到最新版本,现在是 16.4.3 社区版,但没有运气。
Tried to reinstall Microsoft.VisualStudio.Web.CodeGeneration
from NuGet but no luck again.试图从 NuGet 重新安装
Microsoft.VisualStudio.Web.CodeGeneration
但再次没有运气。
Tried to delete .vs folder and no luck again.试图删除 .vs 文件夹,但再次失败。
What could be the problem?可能是什么问题呢? It was working normally before that but the scaffolding stopped working.
在此之前它可以正常工作,但脚手架停止工作。
Thank you谢谢
It turns out it has something with a certain c# language syntax.事实证明,它具有某种 c# 语言语法。 Reading this issue on GitHub helped me to find a workaround.
在 GitHub 上阅读此问题帮助我找到了解决方法。
What helped me fixing the problem is this comment :帮助我解决问题的是这条评论:
By adding this package:通过添加这个包:
Microsoft.CodeAnalysis.CSharp.Workspaces
In the comment, the package version was 3.3.1, but I installed 3.4.0 and it works like a charm.在评论中,包版本是 3.3.1,但我安装了 3.4.0,它的工作原理很吸引人。
I had the same issue.我遇到过同样的问题。 Ubuntu 18.04.5 LTS, Rider EAP 2020.3.
Ubuntu 18.04.5 LTS,Rider EAP 2020.3。 C# 9, dotnet-aspnet-codegenerator version '5.0.1', dotnet 5.0.102.
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)
In desperation mode started trying everything and ran into this and it worked with my configuration.在绝望模式下开始尝试一切并遇到这个问题,它与我的配置一起工作。
In my case I fixed it changing the target of the project to "Net 5.0" (I know this is not always posible) and after that, through (Tools/Manage Nuget Packages) updating these packages to the latest version (in this moment is 5.0.9):在我的情况下,我修复了它,将项目的目标更改为“Net 5.0”(我知道这并不总是可行的),然后通过(工具/管理 Nuget 包)将这些包更新到最新版本(此时是5.0.9):
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.