C# 试图找出模型和DbContext的EntityFramework元数据:';员工';

C# 试图找出模型和DbContext的EntityFramework元数据:';员工';,c#,.net-core,entity-framework-core,asp.net-core-mvc,ubuntu-18.04,C#,.net Core,Entity Framework Core,Asp.net Core Mvc,Ubuntu 18.04,我正在尝试从命令生成驱动程序 dotnet aspnet-codegenerator controller -name EmployeeController -m Employee -dc EmsContext --relativeFolderPath Controllers --useDefaultLayout --referenceScriptLibraries 正在尝试找出模型和DbContext的EntityFramework元数据:“Employee” 在任何文件夹中都找不到与名

我正在尝试从命令生成驱动程序

dotnet aspnet-codegenerator controller -name EmployeeController -m Employee  -dc EmsContext --relativeFolderPath Controllers --useDefaultLayout --referenceScriptLibraries

正在尝试找出模型和DbContext的EntityFramework元数据:“Employee”
在任何文件夹中都找不到与名称MvcControllerWithContext.cshtml匹配的文件:
在Microsoft.VisualStudio.Web.CodeGeneration.ActionInvoker.b_u6_0()上
位于Microsoft.Extensions.CommandLineUtils.CommandLineApplication.Execute(字符串[]args)
位于Microsoft.VisualStudio.Web.CodeGeneration.ActionInvoker.Execute(字符串[]args)
在Microsoft.VisualStudio.Web.CodeGeneration.CodeGenCommand.Execute(字符串[]args)

根据文档,这是最后一步,我从这个框架开始,但我无法摆脱这种状态。我正在使用Ubuntu和整个终端。如果有人能告诉我如何解决这个问题,我将不胜感激。

您使用的是什么版本的dotnetcore SDK?
dotnet——版本

您可能需要安装不同版本的aspnet codegenerator。 一些有用的命令:

dotnet tool uninstall --global dotnet-aspnet-codegenerator
dotnet tool install --global dotnet-aspnet-codegenerator --version 3.1.0
dotnet tool update -g dotnet-aspnet-codegenerator

我的UBUNTU解决方案适用于NetCore3.0、3.1和5.0。 2020年11月27日

ControllerGenerator包含de文件MvcControllerWithContext.cshtml

只需将Templates文件夹Template/ControllerGenerator和Template/ViewGenerator复制到自己的项目中即可

看,本例中的版本是5.0.0
这是丢失文件的路径:/home/$USER/.nuget/packages/microsoft.visualstudio.web.codegenerators.mvc/5.0.0/Templates

当@ericc eacs回答时,您需要复制模板,以防您刚刚学习入门教程(.net core),请确保将文件夹删除到identity模板中,因为生成该文件夹时会出现一些错误。您只需要模板来创建视图和控制器


我可以确认,这个问题至少在11月份就存在了,而且还没有找到解决方案。使用Ubuntu 18.04.5 LTS,Rider EAP 2020.3。C#9,dotnet aspnet代码生成器版本“5.0.1”,dotnet 5.0.102

运行实用程序为Razor pages web app生成crud页面时:

dotnet aspnet-codegenerator razorpage -m GpsSession -dc ApplicationDbContext -udl -outDir Pages/GpsSessions --referenceScriptLibraries
给出了以下输出:

Building project ...
Finding the generator 'razorpage'...
Running the generator 'razorpage'...
Attempting to figure out the EntityFramework metadata for the model and DbContext: 'GpsSession'
A file matching the name Create.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)
建筑工程。。。
正在查找生成器“razorpage”。。。
正在运行发电机“razorpage”。。。
正在尝试找出模型和DbContext的EntityFramework元数据:“GpsSession”
在任何文件夹中都找不到与Create.cshtml名称匹配的文件:
在Microsoft.VisualStudio.Web.CodeGeneration.ActionInvoker.b_u6_0()上
位于Microsoft.Extensions.CommandLineUtils.CommandLineApplication.Execute(字符串[]args)
位于Microsoft.VisualStudio.Web.CodeGeneration.ActionInvoker.Execute(字符串[]args)
在Microsoft.VisualStudio.Web.CodeGeneration.CodeGenCommand.Execute(字符串[]args)

当我在Win10中的同一个存储库上运行相同的命令时,一切都正常工作,生成的crud页面没有任何错误。

它不工作,我使用的版本是dotnet 3.1.302。运行它给我的命令,dotnet工具将更新为3.1.4版。即使我仍然处在同样的情况下:(我在ubuntu上也面临同样的问题。请从这里/home/USER/.nuget/packages/microsoft.visualstudio.web.codegenerators.mvc/5.0.0/Templates复制到您的项目文件夹中。请不要将问题的确认作为答案发布。
Building project ...
Finding the generator 'razorpage'...
Running the generator 'razorpage'...
Attempting to figure out the EntityFramework metadata for the model and DbContext: 'GpsSession'
A file matching the name Create.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)