为什么"dotnet ef migrations add"抛出 Win32Exception?



我有一个实体框架DbContext的dotnet core v3.1项目。当我试图运行:

dotnet ef migrations add someMigrationName

this Exception将被抛出:

System.ComponentModel.Win32Exception (2): No such file or directory
at System.Diagnostics.Process.ForkAndExecProcess(String filename, String[] argv, String[] envp, String cwd, Boolean redirectStdin, Boolean redirectStdout, Boolean redirectStderr, Boolean setCredentials, UInt32 userId, UInt32 groupId, UInt32[] groups, Int32& stdinFd, Int32& stdoutFd, Int32& stderrFd, Boolean usesTerminal, Boolean throwOnNoExec)
at System.Diagnostics.Process.StartCore(ProcessStartInfo startInfo)
at System.Diagnostics.Process.Start()
at System.Diagnostics.Process.Start(ProcessStartInfo startInfo)
at Microsoft.EntityFrameworkCore.Tools.Exe.Run(String executable, IReadOnlyList`1 args, String workingDirectory, Boolean interceptOutput)
at Microsoft.EntityFrameworkCore.Tools.Project.FromFile(String file, String buildExtensionsDir, String framework, String configuration, String runtime)
at Microsoft.EntityFrameworkCore.Tools.RootCommand.Execute(String[] _)
at Microsoft.EntityFrameworkCore.Tools.Commands.CommandBase.<>c__DisplayClass0_0.<Configure>b__0(String[] args)
at Microsoft.DotNet.Cli.CommandLine.CommandLineApplication.Execute(String[] args)
at Microsoft.EntityFrameworkCore.Tools.Program.Main(String[] args)
No such file or directory

我的开发环境是Linux基本操作系统(Ubuntu 18.04.4 LTS)和rider IDE。

这可能是无关的,但当我尝试调试我的xunit测试时,它返回此警告并且不能开始执行。

所有这些命令正常工作并显示所有选项:

  1. dotnet
  2. dotnet ef
  3. dotnet迁移

但是当我使用这些选项时引发异常:

  • dotnetef migrations add
  • dotnet迁移列表

同样,我运行带有详细选项的命令,输出如下:

Using project '/media/navid/9bf0167c-d789-4e06-9e23-4023ec551745/Stuff/Work/SabaCell/venus/Venus.CustomerProfileManagement/Venus.CustomerProfileManagement.csproj'.
Using startup project '/media/navid/9bf0167c-d789-4e06-9e23-4023ec551745/Stuff/Work/SabaCell/venus/Venus.CustomerProfileManagement/Venus.CustomerProfileManagement.csproj'.
Writing '/media/navid/9bf0167c-d789-4e06-9e23-4023ec551745/Stuff/Work/SabaCell/venus/Venus.CustomerProfileManagement/obj/Venus.CustomerProfileManagement.csproj.EntityFrameworkCore.targets'...
dotnet msbuild /target:GetEFProjectMetadata /property:EFProjectMetadataFile=/tmp/tmpUud0Xf.tmp /verbosity:quiet /nologo /media/navid/9bf0167c-d789-4e06-9e23-4023ec551745/Stuff/Work/SabaCell/venus/Venus.CustomerProfileManagement/Venus.CustomerProfileManagement.csproj
System.ComponentModel.Win32Exception (2): No such file or directory
at System.Diagnostics.Process.ForkAndExecProcess(String filename, String[] argv, String[] envp, String cwd, Boolean redirectStdin, Boolean redirectStdout, Boolean redirectStderr, Boolean setCredentials, UInt32 userId, UInt32 groupId, UInt32[] groups, Int32& stdinFd, Int32& stdoutFd, Int32& stderrFd, Boolean usesTerminal, Boolean throwOnNoExec)
at System.Diagnostics.Process.StartCore(ProcessStartInfo startInfo)
at System.Diagnostics.Process.Start()
at System.Diagnostics.Process.Start(ProcessStartInfo startInfo)
at Microsoft.EntityFrameworkCore.Tools.Exe.Run(String executable, IReadOnlyList`1 args, String workingDirectory, Boolean interceptOutput)
at Microsoft.EntityFrameworkCore.Tools.Project.FromFile(String file, String buildExtensionsDir, String framework, String configuration, String runtime)
at Microsoft.EntityFrameworkCore.Tools.RootCommand.Execute(String[] _)
at Microsoft.EntityFrameworkCore.Tools.Commands.CommandBase.<>c__DisplayClass0_0.<Configure>b__0(String[] args)
at Microsoft.DotNet.Cli.CommandLine.CommandLineApplication.Execute(String[] args)
at Microsoft.EntityFrameworkCore.Tools.Program.Main(String[] args)
No such file or directory

这是运行dotnet——info的结果在我的环境中:

.NET Core SDK (reflecting any global.json):
Version:   3.1.405
Commit:    3fae16e62e
Runtime Environment:
OS Name:     elementary
OS Version:  5.1.7
OS Platform: Linux
RID:         linux-x64
Base Path:   /usr/share/dotnet/sdk/3.1.405/
Host (useful for support):
Version: 3.1.11
Commit:  f5eceb8105
.NET Core SDKs installed:
3.1.405 [/usr/share/dotnet/sdk]
.NET Core runtimes installed:
Microsoft.AspNetCore.App 3.1.11 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 3.1.11 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
To install additional .NET Core runtimes or SDKs:
https://aka.ms/dotnet-download

删除符号链接对我不起作用。我不得不重新安装。net-ef工具:

dotnet new tool-manifest

dotnet tool install dotnet-ef

修复了这个问题:)

这对我很有帮助,

我在/usr/local/bin/(macOS)中删除了dotnet symlink

我可以用@bjorn答案来解决这个问题。有一个符号链接在我的/usr/local/bin指向/snap/...,当我试图安装。net sdk与snap,这是不成功的,所以我尝试了不同的方法。只是补充@bjorn的回答,这是我所做的:

检查是否有符号链接:

ls -l /usr/local/bin/

它看起来像这样:

lrwxrwxrwx 1 root root       54 jul 22 09:46 dotnet -> /snap/...

然后删除:

sudo rm /usr/local/bin/dotnet

相关内容

最新更新