Sdk: Entity Framework tools -- "No executable found matching command 'dotnet-ef'"

Created on 15 Feb 2017  路  9Comments  路  Source: dotnet/sdk

Steps to reproduce

  1. Install RC4 VS 2017
  2. Create an ASP.NET Core/ASP.NET Core web project.
  3. Add EF tools to .csproj
    <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.Dotnet" Version="1.0.0-msbuild3-final" />
  4. In project folder run dotnet restore
  5. Try to run EF tools with "dotnet ef" commands.

Expected behavior

EF tools run

Actual behavior

No executable found matching command "dotnet-ef"

Environment data

dotnet --info output:

.NET Command Line Tools (1.0.0-rc4-004802)

Product Information:
 Version:            1.0.0-rc4-004802
 Commit SHA-1 hash:  2384b5f1a8

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.0-rc4-004802

.csproj contents:

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

  <PropertyGroup>
    <TargetFramework>netcoreapp1.1</TargetFramework>
  </PropertyGroup>

  <PropertyGroup>
    <PackageTargetFallback>$(PackageTargetFallback);portable-net45+win8+wp8+wpa81;</PackageTargetFallback>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.0.0" />
    <PackageReference Include="Microsoft.AspNetCore" Version="1.1.0" />
    <PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.1" />
    <PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="1.1.0" />
    <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.0" />
  </ItemGroup>
  <ItemGroup>
    <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.Dotnet" Version="1.0.0-msbuild3-final" />
    <DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="1.0.0-msbuild3-final" />
  </ItemGroup>

</Project>
Bug In PR release blocking

All 9 comments

@rohit21agrawal I just repro'd this locally. I don't see any mention of the tool being restored, nor do I see it in the assets.json file...

This issue was moved to NuGet/Home#4600

Cause

This is caused by a case sensitive comparison on the package id. The repro steps use a lowercase n in Dotnet while the actual package contains an upper case N.
https://www.nuget.org/packages/Microsoft.EntityFrameworkCore.Tools.DotNet/1.1.0-preview4-final

Package ids should be compared case insensitively. The current code causing the issue is here:
https://github.com/dotnet/cli/blob/4b00570f68c0f9709dec97ef6c10f439b7075e96/src/Microsoft.DotNet.Cli.Utils/CommandResolution/ProjectToolsCommandResolver.cs#L152

Fix

After changing to the code below dotnet ef runs fine:

var toolLibrary = toolLockFile.Targets
    .FirstOrDefault(
        t => s_toolPackageFramework == t.TargetFramework)
    ?.Libraries.FirstOrDefault(l => 
                   StringComparer.OrdinalIgnoreCase.Equals(l.Name, toolLibraryRange.Name));

Note the target framework compare was also case sensitive which could cause issues. The best way to check framework equality is to let NuGetFramework perform the comparison using Equals or ==.

Workarounds

Changing the DotNetCliToolReference to use the exact casing also solves the issue.

However since these tools can only be added manually currently, and there is no intellisense or UI to help with this it users may often enter these ids incorrectly.

@piotrpMSFT Can we do a bar check on this bug tomorrow?

@livarcocc yes. Let's have a fix ready.

hey guys, here's ANOTHER reason for dotnet-ef not being found ...a problem with a dotnet new template in RC4: https://github.com/dotnet/cli/issues/5798

im new with this framework , and theres update make me confuse, so how to solve this sir?

@oottoohh update to the dotnet CLI 1.0.1

@emgarten 1.0.1 has the same issue, it's pretty frustrating, pages of google results and no working solution yet...

Was this page helpful?
0 / 5 - 0 ratings