【问题标题】:Attempting to figure out the EntityFramework metadata for the model and DbContext: 'Employee'试图找出模型和 DbContext 的 EntityFramework 元数据:'Employee'
【发布时间】:2020-12-01 07:37:11
【问题描述】:

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

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

Attempting to figure out the EntityFramework metadata for the model and DbContext: 'Employee'
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)

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

【问题讨论】:

  • 我在ubuntu上也遇到了同样的问题。

标签: c# .net-core entity-framework-core asp.net-core-mvc ubuntu-18.04


【解决方案1】:

作为@ericc-eacs 的回答,您需要复制模板,如果您只是按照入门教程(.net 核心)进行操作,请确保将文件夹删除到标识模板中,因为在构建时会给出一些错误。您只需要模板来创建视图和控制器。

【讨论】:

  • 从这里复制它 /home/USER/.nuget/packages/microsoft.visualstudio.web.codegenerators.mvc/5.0.0/Templates 到您的项目文件夹
【解决方案2】:

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

您可能需要安装不同版本的 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

【讨论】:

  • 不行,我用的版本是dotnet 3.1.302。运行它给我的命令,dotnet 工具更新到版本 3.1.4。即使我仍然处于同样的境地:(
【解决方案3】:

我有适用于 net core 3.0、3.1 和 5.0 的 UBUNTU 解决方案。 2020 年 11 月 27 日

ControllerGenerator 包含 de 文件 MvcControllerWithContext.cshtml

您只需复制 Templates 文件夹 Template/ControllerGenerator 和 Template/ViewGenerator 到自己的项目。

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

【讨论】:

    【解决方案4】:

    我可以确认这个问题至少从 11 月开始就存在,并且还没有找到解决方案。使用 Ubuntu 18.04.5 LTS、Rider EAP 2020.3。 C# 9,dotnet-aspnet-codegenerator 版本 '5.0.1',dotnet 5.0.102。

    运行实用程序为 Razor Pages Web 应用构建 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)
    

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

    【讨论】:

    • 请不要发布对问题问题的确认作为答案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-11-17
    • 1970-01-01
    • 2020-08-14
    • 2019-02-08
    • 1970-01-01
    相关资源
    最近更新 更多