Efcore: Problem with dotnet cli ef tools after upgrading to vs 2017 15.4.4 and november .net core rollup

Created on 15 Nov 2017  路  34Comments  路  Source: dotnet/efcore

Not sure if its an EFCore issue or cli

Steps to reproduce

Using Visual Studio Enterprise 2017 (v 15.4.4)

Add migration

dotnet ef migrations add [MigrationName]

Expected behavior

Migration created

Actual behavior

Error message :
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'.

My project is a console library and the content of .csproj file is below:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netcoreapp2.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="System.Reflection.Metadata" Version="1.5.0" />
    <PackageReference Include="Microsoft.Extensions.Configuration" Version="2.0.0" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.0.1" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.0.1" PrivateAssets="All" />
  </ItemGroup>

  <ItemGroup>
    <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.1" />
  </ItemGroup>
</Project>

So i tried to use global.json in the root of my project :

{
  "sdk": {
    "version": "2.0.3"
  }
}

and the error was the same.
But when I changed global.json content to this :

{
  "sdk": {
    "version": "2.0.2"
  }
}

It worked.

closed-fixed type-bug

Most helpful comment

I have the same predicament.

Error is occurring when running:
dotnet ef migrations remove

I was able to work around this by adding this to the EF project:

<PropertyGroup>
   <TargetFramework>netcoreapp2.0</TargetFramework>
   <RuntimeFrameworkVersion>2.0.3</RuntimeFrameworkVersion>
</PropertyGroup>

All 34 comments

I have the same problem.

I have same issue.

Scaffold-DbContext fails silently after that same upgrade to VS 15.4.4

I have the same predicament.

Error is occurring when running:
dotnet ef migrations remove

I was able to work around this by adding this to the EF project:

<PropertyGroup>
   <TargetFramework>netcoreapp2.0</TargetFramework>
   <RuntimeFrameworkVersion>2.0.3</RuntimeFrameworkVersion>
</PropertyGroup>

Can confirm that 2.0.2 workaround works. Not really clear why.

I am pretty sure this is a CLI (dotnet tools) problem, not an EF problem, since I get the same error with dotnet xunit in powershell.

I have cleaned up my system, and only have the 2.0.3 SDK, runtime (x64 and x86) and windows server hosting packs, therefore, @spnm 's solution doesn't work, but @Wind010 's does.

This is probably a dupe of https://github.com/dotnet/cli/issues/7901

@Eilon @natemcmaster @livarcocc Any ideas on this?

I have been trying to repro this for a while now without much success, but this does seem like a CLI problem.

This is a CLI/SDK bug that we now understand. I am duping this one to the one in the CLI: https://github.com/dotnet/cli/issues/7901

We will explain it there why this happens and a workaround and we are figuring out the vehicle to carry a fix for this.

@ajcvickers can you close this bug?

Thanks @livarcocc. Closing.

Re-opening since it looks like there's work to do on our side.

The suggestion in comments don't work for netstandard2.0 project like below.

Windows 10 + VS 2017 15.4.4 + NetCore 2.0.3 SDK

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.Identity" Version="2.0.1" />
    <PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="2.0.1" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="2.0.1" />
  </ItemGroup>

  <ItemGroup>
    <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.1" />
  </ItemGroup>

</Project>

Neither for the 'Scaffold-DbContext' problem in a netcoreapp2.0 project

I used the project config below, and it resolved the issue in my environment (Windows 10 + VS 2017 15.4.4 NetCore 2.0.3 SDK) for 'Scaffold-DbContext'

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netcoreapp2.0</TargetFramework>
    <RuntimeFrameworkVersion>2.0.3</RuntimeFrameworkVersion>
  </PropertyGroup>

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

  <ItemGroup>
    <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.1" />
  </ItemGroup>
</Project>

@lccarvalho This sounds like it could be a different issue. Can you please file a new issue including a sample project that reproduces what you are seeing?

@heku .NET Standard class libraries are not supported directly by the EF tooling. You will need to target an actual framework (e.g. netcoreapp2.0) or specify a startup project that targets a framework. This issue is not about that, but about using a class library that targets on netcoreapp when there is no usable startup project.

I've filed #10338 to improve the silently failing PMC commands.

Workaround

Adding the following to the project should also make it work.

<PropertyGroup>
  <GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
</PropertyGroup>

Tks, @bricelam, can confirm that your workaround works. @ajcvickers: will file new issue with sample project during weekend, please let me know if it is not necessary anymore.

@heku .NET Standard class libraries are not supported directly by the EF tooling. You will need to target an actual framework (e.g. netcoreapp2.0) or specify a startup project that targets a framework. This issue is not about that, but about using a class library that targets on netcoreapp when there is no usable startup project.

Thanks @ajcvickers for response. I specified the startup project indeed锛宐ut it didn't work. I open another issue #10342 to describe my problem in detail.

@ajcvickers no need for a new issue, with help of the messages I could see that there was an error on my Scaffold command, everything works fine for me now

Keeping the issue open for tracking purposes.

There is the same problem with my project, the workaround to resolve it successfully is that remove the item 'C:\Program Files (x86)dotnet' from the Path of Environment Variable because I found I did not install the right netcore version under X86. I have not tried to install the proper version with x86, appreciate that you tell me if you have done that test.

This patch is approved for the Feb 2018 patch. Please send a PR to the appropriate branch, get it reviewed, and merge.

Please consider adding a quirks-mode switch for this change.

I found out that the dotnet cli commands can't run from ClassLibraries it needs .exe in order to execute the command. So I fixed my problem by adding new ConsoleApp (.NET Core) then I've added my ClassLibraries as references to the ConsoleApp. Then run the command dotnet ef --startup-project ../ConsoleApp migrations add init but failed with that Microsoft.EntityFrameworkCore.Design is required in order to execute the command I did it. And it worked

@bricelam your workaround(link) has fixed the same kind of error i got.

Could you please help me understand what this setting does? could you provide some details on how it fixes the issue?

GenerateRuntimeConfigurationFiles forces a *.runtimeconfig.json file to be generated for the project. The file looks like this:

{
  "runtimeOptions": {
    "framework": {
      "name": "Microsoft.NETCore.App",
      "version": "2.0.0"
    }
  }
}

This tells dotnet to execute the code using a version of .NET Core compatible with 2.0.0.

Without the file, EF Tools pass --fx-version 2.0 to dotnet which forces it to run on .NET Core 2.0, but since it's missing a digit, it can't find it.

Setting RuntimeFrameworkVersion (as suggested by @Wind010) changes the value we pass to --fx-version. This will work; however, it means your app will require .NET Core version 2.0.3, so if you publish it to a server that only has version 2.0.0, it'll fail.

thanks!

Still getting this error via Core 2.1.4 SDK within ClassLibrary. When will we be able to add EF to these using NUGET vs. manually as well?

<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.1" />

dotnet ef migrations add InitialCreate
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'.

Does it not seem strange that I have to do this to get it to work on minor versions?

<PropertyGroup>
    <TargetFramework>netcoreapp2.0</TargetFramework
    <RuntimeFrameworkVersion>2.0.5</RuntimeFrameworkVersion>
</PropertyGroup>

@cgountanis i still use the global.json workaround. but yeah, it is mighty annoying.

@cgountanis Unfortunately, the patch containing this fix has not yet been released. Release dates for patches is not something the EF team can influence very much, and there have been various reasons for delaying the patch release that are outside our control. I realize that this is frustrating and I apologize for that. We are, across .NET Core, working on making this process better, so hopefully it won't be such an issue going forward.

Sounds good, will that fix the error when adding the tools via NUGET as well. Right now we have to add that line manually to do migrations etc...

<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.1" />

@cgountanis No, that's a separate NuGet issue, tracked here: https://github.com/NuGet/Home/issues/4190

Was this page helpful?
0 / 5 - 0 ratings