不能使用'dotnet ef ...' - 无法解析指定的框架版本'2.0'

M U*_*M U 17 .net c# entity-framework .net-core asp.net-core

我的项目构建没有任何问题,可以运行没有问题,但我不能使用,dotnet ef migrations因为这个奇怪的错误:

The specified framework version '2.0' could not be parsed
The specified framework 'Microsoft.NETCore.App', version '2.0' was not found.
  - Check application dependencies and target a framework version installed at:
      /
  - Alternatively, install the framework version '2.0'.
Run Code Online (Sandbox Code Playgroud)

我安装了最新的dotnet工具 - SDK 2.1.4和运行时2.0.5.

任何人都可以帮忙吗?我试图在网上找到任何解决方案,但没有找到任何工作......

M U*_*M U 26

在经历了GitHub上的一些问题之后,我终于找到了答案.

看起来这是dotnet CLI本身的问题,而不是EF核心.

如果您遇到此问题,请更新您的.csproj文件以包含运行时框架版本:(在撰写本文时我已2.0.5安装,但请检查您拥有的版本并使用您在计算机上使用的正确版本.

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netcoreapp2.0</TargetFramework>
    <RuntimeFrameworkVersion>2.0.5</RuntimeFrameworkVersion>
  </PropertyGroup>
Run Code Online (Sandbox Code Playgroud)

它正确地解决了这个问题.对我来说,看起来没有指定的csproj文件版本,dotnet CLI正试图回退到2.0.0,由于更新,我们大多数人都没有在计算机上.


Mar*_*scu 8

还有另一个问题.如果您缺少Microsoft.EntityFrameworkCore.Design NuGet包,则会收到相同的错误.因此,请确保从要运行迁移的项目中引用此NuGet包.