Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
spnm opened this issue Nov 15, 2017 · 34 comments
Assignees
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-bug
Milestone

Comments

@spnm
Copy link

spnm commented Nov 15, 2017

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.

@spnm spnm changed the title The specified framework version '2.0' could not be parsed Problem with dotnet cli ef tools after upgrading to vs 2017 15.4.4 and november .net core rollup Nov 15, 2017
@zd-dalibor
Copy link

I have the same problem.

@marcwmiller
Copy link

I have same issue.

@lccarvalho
Copy link

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

@Wind010
Copy link

Wind010 commented Nov 16, 2017

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>

@alexzaytsev-newsroomly
Copy link

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

@jorgeyanesdiez
Copy link

jorgeyanesdiez commented Nov 16, 2017

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.

@jorgeyanesdiez
Copy link

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

@ajcvickers
Copy link
Member

@Eilon @natemcmaster @livarcocc Any ideas on this?

@livarcocc
Copy link

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

@livarcocc
Copy link

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?

@ajcvickers
Copy link
Member

Thanks @livarcocc. Closing.

@bricelam
Copy link
Contributor

bricelam commented Nov 16, 2017

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

@heku
Copy link

heku commented Nov 17, 2017

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>

@lccarvalho
Copy link

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

@marcwmiller
Copy link

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>

@ajcvickers
Copy link
Member

@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.

@ajcvickers ajcvickers added this to the 2.0.4 milestone Nov 17, 2017
@bricelam
Copy link
Contributor

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

@bricelam bricelam added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Nov 17, 2017
@bricelam
Copy link
Contributor

Workaround

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

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

@lccarvalho
Copy link

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
Copy link

heku commented Nov 18, 2017

@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,but it didn't work. I open another issue #10342 to describe my problem in detail.

@lccarvalho
Copy link

@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

@Eilon
Copy link
Member

Eilon commented Dec 1, 2017

Keeping the issue open for tracking purposes.

@cnjimbo
Copy link

cnjimbo commented Dec 12, 2017

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.

@Eilon
Copy link
Member

Eilon commented Jan 17, 2018

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.

@ivanruski
Copy link

ivanruski commented Jan 20, 2018

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

@gitfortee
Copy link

@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?

@bricelam
Copy link
Contributor

bricelam commented Jan 30, 2018

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.

@bricelam
Copy link
Contributor

bricelam commented Jan 30, 2018

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.

@gitfortee
Copy link

thanks!

@cgountanis
Copy link

cgountanis commented Feb 27, 2018

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>

@alexzaytsev-newsroomly
Copy link

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

@ajcvickers
Copy link
Member

@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.

@cgountanis
Copy link

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" />

@ajcvickers
Copy link
Member

@cgountanis No, that's a separate NuGet issue, tracked here: NuGet/Home#4190

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-bug
Projects
None yet
Development

No branches or pull requests