找不到命令“ dotnet ef”? [英] Cannot find command 'dotnet ef'?

查看:99
本文介绍了找不到命令“ dotnet ef”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Arch VScode上使用.NET core 2.0,并试图使EF工具正常工作,但我一直收到找不到命令dotnet ef的错误。我几乎到处都看不到,所有建议都没有用。因此,如果可以的话,请帮忙。

I am using .NET core 2.0 on Arch VScode and trying to get EF tools to work but I keep getting that error 'cannot find command dotnet ef'. I've just about looked everywhere and none of the suggestions worked. So if you can please help that would be much appreciated.

运行'dotnet ef'的结果

The result of running 'dotnet ef'

[wasiim@wasiim-PC WebApiServerApp]$ dotnet ef --help
Cannot find command 'dotnet ef', please run the following command to install

dotnet tool install --global dotnet-ef
[wasiim@wasiim-PC WebApiServerApp]$ dotnet tool list -g
Package Id            Version      Commands        
---------------------------------------------------
dotnet-dev-certs      2.2.0        dotnet-dev-certs
dotnet-ef             2.2.3        dotnet-ef       
[wasiim@wasiim-PC WebApiServerApp]$ 

这是dotnet --info结果,如果有帮助的话

this is the dotnet --info result, if it's of help

[wasiim@wasiim-PC WebApiServerApp]$ dotnet --info
.NET Core SDK (reflecting any global.json):
 Version:   2.2.105
 Commit:    7cecb35b92

Runtime Environment:
 OS Name:     arch
 OS Version:  
 OS Platform: Linux
 RID:         arch-x64
 Base Path:   /opt/dotnet/sdk/2.2.105/

Host (useful for support):
  Version: 2.2.3
  Commit:  6b8ad509b6

.NET Core SDKs installed:
  2.2.105 [/opt/dotnet/sdk]

.NET Core runtimes installed:
  Microsoft.NETCore.App 2.2.3 [/opt/dotnet/shared/Microsoft.NETCore.App]

To install additional .NET Core runtimes or SDKs:
  https://aka.ms/dotnet-download

这是我的.csproj文件

This is my .csproj file

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

  <PropertyGroup>
    <TargetFramework>netcoreapp2.2</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <Folder Include="wwwroot\" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="Lucene.Net.Analysis.Common" Version="4.8.0-beta00005" />
    <PackageReference Include="Lucene.Net.QueryParser" Version="4.8.0-beta00005" />
    <PackageReference Include="Microsoft.AspNetCore.App" Version="2.2.5" />
   <PackageReference Include="Lucene.Net" Version="4.8.0-beta00005" />
    <PackageGroup Include="Microsoft.EntityFrameworkCore.SqlServer" Version="1.1.0" />
    <PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.2.4" />
    <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.3" />

  </ItemGroup>

</Project>


推荐答案

读者注意:如果您尚未安装 dotnet ef ,您需要先安装它: dotnet工具安装--global dotnet-ef 。提问者已经做到了。您需要先执行此操作,然后此答案的其余部分才能有所帮助。

Note to readers: If you haven't install dotnet ef, you need to install it first: dotnet tool install --global dotnet-ef. The question-asker already did that. You need to do that first before the rest of this answer can help.

Linux macOS ,在shell的配置中添加一行:

For Linux and macOS, add a line to your shell's configuration:


  • bash / zsh

export PATH="$PATH:$HOME/.dotnet/tools/"


  • csh / tcsh

    set path = ($path $HOME/.dotnet/tools/)
    


  • 当您启动新的Shell /终端(或下次登录)时, dotnet ef 应该可以工作。

    When you start a new shell/terminal (or the next time you log in) dotnet ef should work.

    对于 Windows

    请参见此问题有关如何添加到 PATH 环境中

    See this question on how to add to the PATH environment variable.

    您需要在<$ c $中添加%USERPROFILE%\.dotnet\tools c>路径。

    You need to add %USERPROFILE%\.dotnet\tools to the PATH.

    .NET Core 3.0(预览版)此失败的版本更能说明问题:

    The .NET Core 3.0 (preview) version of this failure is much more illuminating:

    $ dotnet ef
    Could not execute because the specified command or file was not found.
    Possible reasons for this include:
      * You misspelled a built-in dotnet command.
      * You intended to execute a .NET Core program, but dotnet-ef does not exist.
      * You intended to run a global tool, but a dotnet-prefixed executable with this name could not be found on the PATH.
    

    第二个和第三个都引用 dotnet 试图找到 dotnet-ef 命令,但找不到。如第三点所述, dotnet-ef 不在您的路径之内。

    The second and the third one both refer to dotnet trying to find a dotnet-ef command but can't find it. As the third point says, dotnet-ef is not in your path.

    这里是文档怎么说


    可以将Global Tools安装在默认目录或特定位置。默认目录为:

    Global Tools can be installed in the default directory or in a specific location. The default directories are:

    OS路径

    Linux / macOS $ HOME / .dotnet / tools

    Windows%USERPROFILE%\ .dotnet\tools

    因此,您应该添加 $ HOME /。 dotnet / tools / 到您的 $ PATH

    So, you should add $HOME/.dotnet/tools/ to your $PATH.

    但也请注意docs:


    这些位置是在首次运行SDK时添加到用户路径中的,因此可以直接调用在那里安装的Global Tools。 / p>

    These locations are added to the user's path when the SDK is first run, so Global Tools installed there can be called directly.

    因此,听起来好像出了点问题。如果使用手动tarball安装,则SDK可能已损坏,应将此错误报告给Microsoft。如果您使用分发包,则他们会搞砸了,应该将此错误报告给他们。

    So, it sounds like something went wrong. If you installed using a manual tarball, the SDK screwed up and you should report this bug to Microsoft. If you use a distribution package, they screwed up and you should report this as a bug to them.

    这篇关于找不到命令“ dotnet ef”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆