#c# #.net #linux #rider
Вопрос:
Я использую JetBrains Rider в Linux. Всякий раз , когда я запускаю dotnet ef migrations add InitialCreate
, он делает это в терминале и выдает мне эту ошибку:
Build started...
Build succeeded.
Xlib: extension "NV-GLX" missing on display ":0.0".
Xlib: extension "NV-GLX" missing on display ":0.0".
0104:fixme:ntdll:NtQuerySystemInformation info_class SYSTEM_PERFORMANCE_INFORMATION
System.PlatformNotSupportedException: Cannot find 'Mono.SystemDependencyProvider, System' dependency
at Mono.DependencyInjector.get_SystemProvider () [0x0003d] in <a9da539eb2f94b1a84ab84db52450d46>:0
at System.Security.Cryptography.X509Certificates.X509Helper.get_CertificateProvider () [0x00000] in <a9da539eb2f94b1a84ab84db52450d46>:0
at System.Security.Cryptography.X509Certificates.X509Helper.Import (System.Byte[] rawData, Microsoft.Win32.SafeHandles.SafePasswordHandle password, System.Security.Cryptography.X509Certificates.X509KeyStorageFlags keyStorageFlags)
[0x00000] in <a9da539eb2f94b1a84ab84db52450d46>:0
at System.Security.Cryptography.X509Certificates.X509Certificate..ctor (System.String fileName, System.String password, System.Security.Cryptography.X509Certificates.X509KeyStorageFlags keyStorageFlags) [0x0003e] in <a9da539eb2f94
b1a84ab84db52450d46>:0
at System.Security.Cryptography.X509Certificates.X509Certificate..ctor (System.String fileName) [0x00000] in <a9da539eb2f94b1a84ab84db52450d46>:0
at System.Security.Cryptography.X509Certificates.X509Certificate.CreateFromSignedFile (System.String filename) [0x00000] in <a9da539eb2f94b1a84ab84db52450d46>:0
at System.Security.Policy.Evidence.GetDefaultHostEvidence (System.Reflection.Assembly a) [0x00097] in <a9da539eb2f94b1a84ab84db52450d46>:0
at System.AppDomain.get_Evidence () [0x00045] in <a9da539eb2f94b1a84ab84db52450d46>:0
at (wrapper remoting-invoke-with-check) System.AppDomain.get_Evidence()
at System.AppDomain.CreateDomain (System.String friendlyName, System.Security.Policy.Evidence securityInfo, System.AppDomainSetup info) [0x000de] in <a9da539eb2f94b1a84ab84db52450d46>:0
at Microsoft.EntityFrameworkCore.Tools.AppDomainOperationExecutor..ctor (System.String assembly, System.String startupAssembly, System.String projectDir, System.String dataDirectory, System.String rootNamespace, System.String lang
uage, System.String[] remainingArguments) [0x0004c] in <27660142d7fa4f02b91c8d5e3bfbdb6d>:0
at Microsoft.EntityFrameworkCore.Tools.Commands.ProjectCommandBase.CreateExecutor (System.String[] remainingArguments) [0x00042] in <27660142d7fa4f02b91c8d5e3bfbdb6d>:0
at Microsoft.EntityFrameworkCore.Tools.Commands.MigrationsAddCommand.Execute (System.String[] args) [0x00000] in <27660142d7fa4f02b91c8d5e3bfbdb6d>:0
at Microsoft.EntityFrameworkCore.Tools.Commands.CommandBase <>c__DisplayClass0_0.<Configure>b__0 (System.String[] args) [0x0003b] in <27660142d7fa4f02b91c8d5e3bfbdb6d>:0
at Microsoft.DotNet.Cli.CommandLine.CommandLineApplication.Execute (System.String[] args) [0x000df] in <27660142d7fa4f02b91c8d5e3bfbdb6d>:0
at Microsoft.EntityFrameworkCore.Tools.Program.Main (System.String[] args) [0x0002e] in <27660142d7fa4f02b91c8d5e3bfbdb6d>:0
Cannot find 'Mono.SystemDependencyProvider, System' dependency
Если кто-нибудь знает ответ, спасибо!
Ответ №1:
У меня была та же проблема в проекте веб-API .net 5
Инструмент EF просматривает метод CreateWebHostBuilder и возвращает ошибку, если его не удалось найти.
directories:
/src
|-- /YourPorject.Infrastructure
|-- /YourPorject.API
public static IHostBuilder CreateWebHostBuilder(string[] args)
{
return Host.CreateDefaultBuilder(args)
.ConfigureAppConfiguration((context, config) =>
{
config.AddJsonFile(
context.HostingEnvironment.ContentRootPath $"/Config/appsettings-dev.json",
false, false);
})
.ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup<Startup>(); });
}
Используйте bash для создания и обновления базы данных
cd src/
dotnet ef migrations add Init
--project YourPorject.Infrastructure/YourPorject.Infrastructure.csproj
--startup-project YourPorject.API/YourPorject.API.csproj
-o ./Repositories/Migrations/
cd src/
dotnet ef database update
--project YourPorject.Infrastructure/YourPorject.Infrastructure.csproj
--startup-project YourPorject.API/YourPorject.API.csproj
Используйте эти пакеты (это важно)
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.8" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="5.0.8" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="5.0.8" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.8" />
</ItemGroup>