dotnet/efcore

Can't install EFCore.Tools.DotNet package via Package Mgr to .NET Core or .NET Standard class library in VS2017 (windows)

Closed this issue ยท 29 comments

Describe what is not working as expected.
In latest VS2017 (Mar 9 update ), I cannot add the DotNet tools package to a .NET Core project or a .NET Stnadard class library project either via Package Manager or directly in csproj.

The same behavior occurs in the RTW version from Mar 7.

Is this by design? Are you forcing us to install the PowerShell tools if we are using VS2017? (I hope not ๐Ÿ˜‰ )

Package Manager throws this error:
Package 'Microsoft.EntityFrameworkCore.Tools.DotNet 1.0.0' has a package type 'DotnetCliTool' that is not supported by project 'ClassLibrary1.

Steps to reproduce

New solution.
Add new project, .NET Core, ClassLibrary (.nET Core).
Here is the default csproj:

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

Open Package Manager via "Manage packages" context menu.
Filter on EntityFrameworkCore.Tools
Select Tools.DotNet package and install.
Error pane displays:"Package 'Microsoft.EntityFrameworkCore.Tools.DotNet 1.0.0' has a package type 'DotnetCliTool' that is not supported by project 'ClassLibrary1." and the csproj is not modified.

Open csproj.
Add in:

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

Save & rebuild, this is fine.

I have the same results (failed via Package Manager, ok via csproj) with a .NET Standard Library project.

Further technical details

EF Core version:

>dotnet --info
.NET Command Line Tools (1.0.1)

Product Information:
 Version:            1.0.1
 Commit SHA-1 hash:  005db40cd1

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.14393
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\1.0.1

Database Provider: (e.g. Microsoft.EntityFrameworkCore.SqlServer)
Operating system: Windows 10
IDE: Microsoft Visual Studio Enterprise 2017, Version 15.0.26228.4 D15RTWSVC
Nuget Package Manager 4.0.0

External dupe: NuGet/Home#4190

In their own words:

We punted the work to support tools installs via the UI with the idea that tools will be installed by default with new projects ... and that people can edit the csproj if an addition is needed.

BTW, adding the DotNetCliToolReference entry is the right workaround.

Are you forcing us to install the PowerShell tools if we are using VS2017?

No, but we do recommend it since they give you a more integrated experience:

  • Detects the startup project.
  • Opens files in the IDE.
  • Has tab-expansion for command arguments. (like projects, DbContexts, providers, migrations, etc.)

well, boo. (shakes fist (in most friendly manner of course) at @rrelyea for punting). I think that if someone with my level of experience spent 1/2 hour scratching her head over this, it's going to be hard for others. But okay. Will be sure to mention all of these points out as I'm revising my efcore course)

related...as I was typing the last response, someone asked about adding the CLI package from the dotnet command line via dotnet packages add. My guess is that here, also, manually editing csproj is required? If you want to reply to that comment, it's here: thedatafarm.com/data-access/no-executable-found-matching-command-dotnet-ef/#comment-61861

I'm not sure on that one. I've never tried dotnet add package Microsoft.EntityFrameworkCore.Tools.DotNet...

Well, the command succeeds, but it doesn't do it right:

<ItemGroup>
  <PackageReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="1.0.0" />
</ItemGroup>

Filed dotnet/cli#5998

This is still broken with .Net Standard 2.0

Yep. Super disappointing since it used to work with xproj. Let the NuGet team know it's important on NuGet/Home#4190.

this is still not working for me either, I tried updating it today and it failed with the same error as above.

We're still waiting for the NuGet bug to be fixed.

Still borked :|

You can add it manually in your .csproj file until it is fixed.

  1. Open your .csproj file in a text editor of your choice.
  2. Insert the line <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="1.0.1" /> within an open and close ItemGroup tag.
  3. Save the file and restore packages.

@Bargsteen The latest version is 1.0.1. It works when manually added too, right?

Iยดll try it later myself to confirm, but it should also work.

Yes, it works for 1.0.1 as well.

Thanks @Bargsteen, that worked for me too with .NET Standard 2.0 and EF Core 2.0.

image

PLease am new to aspnet core 2.0, kindly helpl with this error.
i cant install microsoft.entityframeworkcore.tools.dotnet,

@kessysam - You are mixing up packages and runtime versions. You are trying to use EF 6.1 in netcoreapp2.0 project which is not supported. You need to use .NET Framework. You can use EF6 in aspnet core project targeting .net framework. But Microsoft.EntityFrameworkCore.Tools.DotNet package is for EF Core and not for EF6. Can you file a new issue with details of your project and packages you want to use.

@smitpatel The project am working basically is a web api, that adds identity to the api....i only installed entityframeworkcore packages, but seems there is a conflict with entityframework packages.....How do i specify which framework to use when running "add-migration" command in pmc?

screen shot 2018-02-19 at 3 52 11 pm

Hello. I have a problem in making database on my Terminal. I already update nugets in VS2017 for MAC. Version for package Microsoft.EntityFrameworkCore.Tools.DotNet could not be resolved.

@hkumipig - Please show content of demo.csproj file.

@hkumipig - You are hitting #10957
Please run dotnet restore on CLI manually.

CLI commands can be found here:
https://docs.microsoft.com/en-us/ef/core/miscellaneous/cli/dotnet

For example, to add a migration it is not

dotnet ef Add-Migration...

but

-- add a migration named "InitialCreate"
dotnet ef migrations add InitialCreate

Note that if the migrations are in a separate project, then you'll need to add "--project NAME" and substitute NAME with the migration project's name.

@bricelam @smitpatel getting this error while adding nuget package Tools.DotNet, project is targetting .Netcore 2.0. Is there a fix for this issue?
Package 'Microsoft.EntityFrameworkCore.Tools.DotNet 2.0.2' has a package type 'DotnetCliTool' that is not supported by project 'APIService'.

@bricelam per your comment here (#10457)

Please modify your comment on this thread that says to that says to use:

PackageReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="1.0.0"

Because I for one went that route and then had to find the other solution in your other comment that says use:

DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet"...

Also I saw several comments on a couple of posts asking if adding via GUI worked it did not for me.