c# - 您的启动项目未引用 Microsoft.EntityFrameworkCore.Design

标签 c# visual-studio entity-framework-core nuget entity-framework-migrations

我的解决方案中有 2 个项目,我有一个安装了 Entity Framework Core 的项目:

enter image description here

在另一个 ASP.NET Web API 项目中我有这些包:

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="Antlr" version="3.5.0.2" targetFramework="net461" />
  <package id="Microsoft.ApplicationInsights" version="2.5.1" targetFramework="net461" />
  <package id="Microsoft.ApplicationInsights.Agent.Intercept" version="2.4.0" targetFramework="net461" />
  <package id="Microsoft.ApplicationInsights.DependencyCollector" version="2.5.1" targetFramework="net461" />
  <package id="Microsoft.ApplicationInsights.PerfCounterCollector" version="2.5.1" targetFramework="net461" />
  <package id="Microsoft.ApplicationInsights.Web" version="2.5.1" targetFramework="net461" />
  <package id="Microsoft.ApplicationInsights.WindowsServer" version="2.5.1" targetFramework="net461" />
  <package id="Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel" version="2.5.1" targetFramework="net461" />
  <package id="Microsoft.AspNet.Mvc" version="5.2.4" targetFramework="net461" />
  <package id="Microsoft.AspNet.Razor" version="3.2.4" targetFramework="net461" />
  <package id="Microsoft.AspNet.TelemetryCorrelation" version="1.0.0" targetFramework="net461" />
  <package id="Microsoft.AspNet.Web.Optimization" version="1.1.3" targetFramework="net461" />
  <package id="Microsoft.AspNet.WebApi" version="5.2.4" targetFramework="net461" />
  <package id="Microsoft.AspNet.WebApi.Client" version="5.2.4" targetFramework="net461" />
  <package id="Microsoft.AspNet.WebApi.Core" version="5.2.4" targetFramework="net461" />
  <package id="Microsoft.AspNet.WebApi.HelpPage" version="5.2.4" targetFramework="net461" />
  <package id="Microsoft.AspNet.WebApi.WebHost" version="5.2.4" targetFramework="net461" />
  <package id="Microsoft.AspNet.WebPages" version="3.2.4" targetFramework="net461" />
  <package id="Microsoft.CodeDom.Providers.DotNetCompilerPlatform" version="2.0.0" targetFramework="net461" />
  <package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net461" />
  <package id="Newtonsoft.Json" version="11.0.1" targetFramework="net461" />
  <package id="System.Diagnostics.DiagnosticSource" version="4.4.1" targetFramework="net461" />
  <package id="WebGrease" version="1.6.0" targetFramework="net461" />
</packages>

当我在 PMC 中运行 Add-Migration 时:

Your startup project 'API' doesn't reference Microsoft.EntityFrameworkCore.Design. This package is required for the Entity Framework Core Tools to work. Ensure your startup project is correct, install the package, and try again.

我在启动项目而不是将包含所有实体的数据项目中安装了 Microsoft.EntityFrameworkCore.Design,现在它可以工作了,项目应该这样设置吗?

最佳答案

我找到了解决方案 here .

简而言之,编辑您的 csproj 文件,并将以下条目添加到您的 PropertyGroup 部分:

<GenerateRuntimeConfigurationFiles>True</GenerateRuntimeConfigurationFiles>

关于c# - 您的启动项目未引用 Microsoft.EntityFrameworkCore.Design,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52536588/

相关文章:

c# - 多对多 EF Core 关系 - 为什么它尝试将实体插入到不同的表中?

c# - Entity Framework Core 创建和更新字段

c# - ArgumentException:C# 中的 'Illegal characters in path'

C# Window Form - 如何自动备份数据库并将其发送到在线 Phpmyadmin 或通过电子邮件

c# - C#中特殊字符的Url编码方法

c# - 如何将参数从 javascript 传递到通用处理程序?

c# - Roslyn 诊断分析器的诊断未反射(reflect)在 Visual Studio 实例中

visual-studio - Roslyn 中的对话窗口

c++ - 在 Visual Studio 监 window 口中显示数组范围,包括特殊字符。

entity-framework-core - 具有自定义连接的全局查询