Was*_*ama 25 c# entity-framework csproj .net-core asp.net-core
我在Arch VScode上使用.NET Core 2.0,并尝试使EF工具正常工作,但我不断收到该错误“找不到命令dotnet ef”。我只是到处看,所有建议都没有。因此,如果可以的话,请您提供帮助。
运行“ 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]$
Run Code Online (Sandbox Code Playgroud)
这是dotnet --info结果,如果有帮助的话
[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
Run Code Online (Sandbox Code Playgroud)
这是我的.csproj文件
<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>
Run Code Online (Sandbox Code Playgroud)
Gar*_*rth 76
In my case, the tools folder didn't exist inside %USERPROFILE%\.dotnet\ so I had to run the command dotnet tool install --global dotnet-ef to install dotnet ef. Then I was able to run dotnet ef...
This was the result of the above install command:
Oma*_*jid 16
对于Linux和macOS,在shell的配置中添加一行:
bash/ zsh:
export PATH="$PATH:$HOME/.dotnet/tools/"
Run Code Online (Sandbox Code Playgroud)csh/ tcsh:
set path = ($path $HOME/.dotnet/tools/)
Run Code Online (Sandbox Code Playgroud)当您启动新的外壳程序/终端时(或下次登录时),dotnet ef应该可以使用。
对于Windows:
有关如何添加到环境变量的信息,请参见此问题PATH。
您需要添加%USERPROFILE%\.dotnet\tools到中PATH。
此故障的.NET Core 3.0(预览版)更能说明问题:
$ 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.
Run Code Online (Sandbox Code Playgroud)
第二个和第三个都涉及dotnet尝试查找dotnet-ef命令,但是找不到它。如第三点所述,dotnet-ef不在您的道路上。
这是文档所说的:
可以将Global Tools安装在默认目录或特定位置。默认目录为:
OS Path
Linux/macOS $HOME/.dotnet/tools
Windows %USERPROFILE%\.dotnet\tools
因此,您应该添加$HOME/.dotnet/tools/到中$PATH。
但也请注意文档中的这一部分:
这些位置会在首次运行SDK时添加到用户的路径中,因此可以直接调用在那里安装的Global Tools。
因此,听起来好像出了点问题。如果使用手动tarball安装,则SDK可能已损坏,应将此错误报告给Microsoft。如果您使用分发包,他们会搞砸,您应该将此作为错误报告给他们。
我已经尝试了所有以前的答案,但它在我的 Mac 上无法使用最新的macOS v10.15 (Catalina) 更新。
例如,如果您使用 .NET Core 3 版本,则需要运行以下命令:
export PATH="$PATH:$HOME/.dotnet/tools/"
export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=false
export DOTNET_ADD_GLOBAL_TOOLS_TO_PATH=true
dotnet tool install --global dotnet-ef --version 3.0.0
Run Code Online (Sandbox Code Playgroud)
dotnet ef database update
Run Code Online (Sandbox Code Playgroud)
如果上面的命令给你一个错误,请按照以下步骤操作。
检查路径 %USERPROFILE%.dotnet\ 是否存在
如果没有,则运行以下命令
dotnet tool install -g dotnet-ef
Run Code Online (Sandbox Code Playgroud)
现在再次检查路径并为以下路径设置环境变量
%USERPROFILE%\.dotnet\tool
Run Code Online (Sandbox Code Playgroud)
现在在 cmd 中,设置数据库上下文文件所在的路径,然后运行以下命令
dotnet ef database update
Run Code Online (Sandbox Code Playgroud)
注意:它适用于 .NET Core 3.0。
关于路径修复:
请注意,这会将路径添加到用户路径,而不是系统路径环境变量。从 Visual Studio 启动“开发人员命令提示符”或“开发人员 PowerShell”时,它不使用用户路径变量。您还需要将其添加到系统环境变量中。
此外,您需要重新启动 Visual Studio Code 才能使更改生效。
| 归档时间: |
|
| 查看次数: |
11439 次 |
| 最近记录: |