The specified framework 'Microsoft.NETCore.App', version '2.1' was not found
Asked Answered
H

3

18

I am developing an Angular 6 application in dotNet Core 2.1. Everything is working flawlessly, until I got to setting up EFCore. All my models are defined and context created. Running dotnet ef migrations add InitialCreate gives me the "The specified framework 'Microsoft.NETCore.App', version '2.1' was not found" error.

I have searched and read all the posts I could find that has this error across various versions of dotNet Core. Nothing is working to resolve this issue for me.

I have various versions of dotNet Core App installed. Looking at "C:\Program Files\dotnet\shared\Microsoft.NETCore.App" I have the following:

-1.0.4
-1.0.5
-1.1.1
-1.1.2
-2.0.0
-2.0.3
-2.0.5
-2.0.6
-2.0.7
-2.0.9
-2.1.0
-2.1.4
-2.1.5
-2.1.6

"C:\Program Files\dotnet" appears as the first path in my System PATH variable.

Downgrading all the projects in my solution to dotNet Core 2.0, running the command results in exactly the same error, referring to version 2.0.

Any advise would be greatly appreciated...

The csproj file for my EF project is as follows:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netcoreapp2.1</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.1.4" />
  </ItemGroup>

  <ItemGroup>
    <ProjectReference Include="..\*********.Contracts\*********.Contracts.csproj" />
  </ItemGroup>

  <ItemGroup>
    <Reference Include="System">
      <HintPath>System</HintPath>
    </Reference>
    <Reference Include="System.Data">
      <HintPath>System.Data</HintPath>
    </Reference>
    <Reference Include="System.Xml">
      <HintPath>System.Xml</HintPath>
    </Reference>
  </ItemGroup>
</Project>
Hasin answered 18/11, 2018 at 10:9 Comment(14)
Can you show your project file? It's likely that there's a version reference there somewhere that's causing trouble...Marconigraph
Try to install this Nuget package to the project. Even though you don’t use it in that projectBecnel
@TomasAschan: Do you mean the csproj file? I have multiples, designating multi layers to the application. Would it then be the project where EF resides?Hasin
@OlegI: If you are referring to the Microsoft.NETCore.App nuget package, it is installed in the EFCore project.Hasin
@Hasin try to install it in every project in your solution to start with. I had an exactly same issue. I had to install it to my unit test project even though it was compiling without it. And that resolved the problemBecnel
@OlegI: All my projects were created as Class Libraries (.NET Core) and already has the nuget package installed. The package is also version 2.1.0 for all of them. The Angular project was created as a ASP.NET Core Web Application and also has the nuget package with the same version.Hasin
@Hasin The relevant project flie is the one in which's folder you invoke dotnet ef. (I assume that's in the project where you also have your EF classes, e.g. the DbContext.)Marconigraph
@TomasAschan: I have added the project file as requested.Hasin
Check out Entity Framework Core tools reference - .NET CLI. Have you followed the Installing the tools instructions? What do you get if you run dotnet ef command to verify the installation?Maximomaximum
@IvanStoev: Running "dotnet restore" and then "dotnet ef" displays: "Entity Framework Core .NET Command-line tools 2.1.4-rtm-31024"Hasin
Ok, so the installation seems to be ok. The next step would be to check Using the tools section - target project and startup project. What happens if you specify them explicitly via --project and --startup-project, and also add --verbose option?Maximomaximum
Holy $h1t, thanks Ivan. Reading through installing the tools again, I ran "dotnet add package Microsoft.EntityFrameworkCore.Design" and it seems to have solved the problem. It added "<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.1.4" />" to my project file. As always, the Microsoft errors are extremely vague and often does not point to the real problem at all...Hasin
@IvanStoev If you add your suggestion as an answer, I'll accept it. Thanks again.Hasin
@Hasin You are welcome, glad being helpful :) But I think posting your own self answer is more appropriate here. Cheers.Maximomaximum
H
15

To solve the issue, I had to install the Microsoft.EntityFrameworkCore.Design package. The installing-the-tools section of the documentation states that it is not necessary to do so for Asp.Net Core 2.1+:

ASP.NET Core 2.1+

  • Install the current .NET Core SDK. The SDK has to be installed even if you have the latest version of Visual Studio 2017.
    This is all that is needed for ASP.NET Core 2.1+ because the Microsoft.EntityFrameworkCore.Design package is included in the Microsoft.AspNetCore.App metapackage.

My solution is broken up into different projects; I created a Class Library project where my EF Core installation resides.

Since it is not an Asp.Net Core project (It's a Class Library as stated before), it also required the Microsoft.EntityFrameworkCore.Design package to be installed.

The package can be installed using: dotnet add package Microsoft.EntityFrameworkCore.Design

Thanks to Ivan Stoev for pointing me in the direction of the documentation.
The error was no help at all, sending me on a wild goose chase to try and find the underlying problem. I hope this will be useful to someone else.

Hasin answered 19/11, 2018 at 12:7 Comment(0)
T
2

I have the same issue when running

dotnet ef dbcontext info -s ProjectWeb.csproj

Although the version it is looking is 2.1.17:

The framework 'Microsoft.NETCore.App', version '2.1.17' was not found.

Fortunately, upon digging into the issue, there was a suggestion to download it here:

https://aka.ms/dotnet-core-applaunch?framework=Microsoft.NETCore.App&framework_version=2.1.17&arch=x64&rid=win10-x64

Which will redirect you to this link:

https://dotnet.microsoft.com/download/dotnet-core/2.1/runtime/?utm_source=getdotnetcore&utm_medium=referral

After installation, the issue was fixed on my side.

Tillo answered 17/4, 2020 at 23:50 Comment(0)
P
0

Please also check your BundlerMinifier:

   <ItemGroup>
       <DotNetCliToolReference Include="BundlerMinifier.Core" Version="3.2.449" />
   </ItemGroup>

If you are using an older version, that is likely the culprit... see latest versions here: https://www.nuget.org/packages/BundlerMinifier.Core/

Pascasia answered 4/3, 2021 at 21:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.