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

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

问题描述

我在 Arch Linux/Visual Studio Code 上使用 .NET Core 2.0 并且正在尝试让 EF 工具工作,但我不断收到错误:

<块引用>

找不到命令 dotnet ef

我几乎四处看了看,但没有一个建议奏效.

运行'dotnet ef'的结果:

[wasiim@wasiim-PC WebApiServerApp]$ dotnet ef --help找不到命令dotnet ef",请运行以下命令进行安装dotnet 工具安装 --global dotnet-ef[wasiim@wasiim-PC WebApiServerApp]$ dotnet 工具列表 -g包 ID 版本命令--------------------------------------------------——dotnet-dev-certs 2.2.0 dotnet-dev-certsdotnet-ef 2.2.3 dotnet-ef[wasiim@wasiim-PC WebApiServerApp]$

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

[wasiim@wasiim-PC WebApiServerApp]$ dotnet --info.NET Core SDK(反映任何 global.json):版本:2.2.105提交:7cecb35b92运行环境:操作系统名称:arch操作系统版本:操作系统平台:LinuxRID:arch-x64基本路径:/opt/dotnet/sdk/2.2.105/主机(用于支持):版本:2.2.3提交:6b8ad509b6已安装的 .NET Core SDK:2.2.105 [/opt/dotnet/sdk]安装的 .NET Core 运行时:Microsoft.NETCore.App 2.2.3 [/opt/dotnet/shared/Microsoft.NETCore.App]要安装其他 .NET Core 运行时或 SDK:https://aka.ms/dotnet-download

这是我的 .csproj 文件:

<属性组><TargetFramework>netcoreapp2.2</TargetFramework></PropertyGroup><项目组><文件夹包含=wwwroot"/></项目组><项目组><PackageReference Include=Lucene.Net.Analysis.Common"版本=4.8.0-beta00005"/><PackageReference Include="Lucene.Net.QueryParser";版本=4.8.0-beta00005"/><PackageReference Include="Microsoft.AspNetCore.App";版本=2.2.5"/><PackageReference Include=Lucene.Net"版本=4.8.0-beta00005"/><PackageGroup Include="Microsoft.EntityFrameworkCore.SqlServer";版本=1.1.0"/><PackageReference Include=Microsoft.AspNetCore.Razor.Design"版本=2.2.0"私有资产=全部"/><PackageReference Include="Microsoft.EntityFrameworkCore.Design";版本=2.2.4"/><DotNetCliToolReference Include=Microsoft.EntityFrameworkCore.Tools.DotNet"版本=2.0.3"/></项目组></项目>

解决方案

读者注意事项:如果您还没有安装dotnet ef,需要先安装:dotnet tool install--global dotnet-ef.提问者已经这样做了.在本答案的其余部分提供帮助之前,您需要先执行此操作.

如何解决这个问题

对于 Linuxma​​cOS,在 shell 的配置中添加一行:

  • bash/zsh:

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

  • csh/tcsh:

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

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

对于 Windows:

参见这个问题,了解如何添加PATH 环境变量.

您需要将 %USERPROFILE%.dotnet ools 添加到 PATH.

发生了什么事?

此故障的 .NET Core 3.0(预览版)版本更具启发性:

$ dotnet ef无法执行,因为找不到指定的命令或文件.可能的原因包括:* 您拼错了内置的 dotnet 命令.* 您打算执行 .NET Core 程序,但 dotnet-ef 不存在.* 您打算运行一个全局工具,但在 PATH 中找不到具有此名称的 dotnet 前缀的可执行文件.

第二个和第三个都指的是 dotnet 试图找到一个 dotnet-ef 命令但找不到它.正如第三点所说,dotnet-ef 不在您的路径中.

以下是文档说明::><块引用>

全局工具可以安装在默认目录或特定位置.默认目录为:

操作系统路径

Linux/macOS $HOME/.dotnet/tools

Windows %USERPROFILE%.dotnet ools

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

但还要注意文档中的这一部分:

<块引用>

这些位置是在SDK第一次运行时添加到用户路径中的,所以安装在那里的Global Tools可以直接调用.

所以,听起来好像出了点问题.如果您使用手动 tarball 进行安装,则 SDK 会出错,您应该将此错误报告给 Microsoft.如果您使用分发包,他们就会搞砸,您应该将此作为错误报告给他们.

I am using .NET Core 2.0 on Arch Linux / Visual Studio Code and am trying to get EF tools to work, but I keep getting the error:

cannot find command dotnet ef

I've just about looked everywhere and none of the suggestions worked.

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]$

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

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>

解决方案

Note to readers: If you haven't installed 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.

How to fix this

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

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

For Windows:

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

You need to add %USERPROFILE%.dotnet ools to the PATH.

What's going on?

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.

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.

Here's what the docs say:

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

OS Path

Linux/macOS $HOME/.dotnet/tools

Windows %USERPROFILE%.dotnet ools

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

But also note this part from docs:

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

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天全站免登陆