环境 - 使用VS for Mac的Mac OS。
项目结构: 根
错误讯息:
无法加载文件或程序集'MyApp.Core.dll,Culture = neutral, 公钥=空”。系统找不到指定的文件。
执行命令:
dotnet ef migrations add initial -v -p ../MyApp.Core/
命令执行输出:
Using project '../MyApp.Core/MyApp.Core.csproj'.
Using startup project '/Users/r/WorkingDir/MyCompany/MyAppApp/MyAppApp/MyAppApp.Web/MyAppApp.Web.csproj'.
Writing '../MyApp.Core/obj/MyApp.Core.csproj.EntityFrameworkCore.targets'...
dotnet msbuild /target:GetEFProjectMetadata /property:EFProjectMetadataFile=/var/folders/cf/3tt15lc91fb0bkyrtkkh9rzw0000gn/T/tmpd5ub99.tmp /verbosity:quiet /nologo ../MyApp.Core/MyApp.Core.csproj
Writing '/Users/r/WorkingDir/MyCompany/MyAppApp/MyAppApp/MyAppApp.Web/obj/MyAppApp.Web.csproj.EntityFrameworkCore.targets'...
dotnet msbuild /target:GetEFProjectMetadata /property:EFProjectMetadataFile=/var/folders/cf/3tt15lc91fb0bkyrtkkh9rzw0000gn/T/tmpUguanx.tmp /verbosity:quiet /nologo /Users/r/WorkingDir/MyCompany/MyAppApp/MyAppApp/MyAppApp.Web/MyAppApp.Web.csproj
dotnet build /Users/r/WorkingDir/MyCompany/MyAppApp/MyAppApp/MyAppApp.Web/MyAppApp.Web.csproj /p:GenerateRuntimeConfigurationFiles=True /verbosity:quiet /nologo
Build succeeded.
0 Warning(s)
0 Error(s)
Time Elapsed 00:00:05.78
dotnet exec --depsfile /Users/r/WorkingDir/MyCompany/MyAppApp/MyAppApp/MyAppApp.Web/bin/Debug/netcoreapp2.0/MyAppApp.Web.deps.json --additionalprobingpath /Users/r/.nuget/packages --additionalprobingpath /usr/local/share/dotnet/sdk/NuGetFallbackFolder --runtimeconfig /Users/r/WorkingDir/MyCompany/MyAppApp/MyAppApp/MyAppApp.Web/bin/Debug/netcoreapp2.0/MyAppApp.Web.runtimeconfig.json /Users/r/.nuget/packages/microsoft.entityframeworkcore.tools.dotnet/2.0.2/tools/netcoreapp2.0/ef.dll migrations add initial --assembly /Users/r/WorkingDir/MyCompany/MyAppApp/MyAppApp/MyAppApp.Web/bin/Debug/netcoreapp2.0/MyApp.Core.dll --startup-assembly /Users/r/WorkingDir/MyCompany/MyAppApp/MyAppApp/MyAppApp.Web/bin/Debug/netcoreapp2.0/MyAppApp.Web.dll --project-dir /Users/r/WorkingDir/MyCompany/MyAppApp/MyAppApp/MyApp.Core/ --verbose --root-namespace MyApp.Core
Using assembly 'MyApp.Core'.
Using startup assembly 'MyAppApp.Web'.
Using application base '/Users/r/WorkingDir/MyCompany/MyAppApp/MyAppApp/MyAppApp.Web/bin/Debug/netcoreapp2.0'.
Using working directory '/Users/r/WorkingDir/MyCompany/MyAppApp/MyAppApp/MyAppApp.Web'.
Using root namespace 'MyApp.Core'.
Using project directory '/Users/r/WorkingDir/MyCompany/MyAppApp/MyAppApp/MyApp.Core/'.
Finding DbContext classes...
Finding IDesignTimeDbContextFactory implementations...
Finding application service provider...
Finding BuildWebHost method...
Using environment 'Development'.
Using application service provider from BuildWebHost method on 'Program'.
info: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[0]
User profile is available. Using '/Users/r/.aspnet/DataProtection-Keys' as key repository; keys will not be encrypted at rest.
Found DbContext 'MyAppUserDbContext'.
Finding DbContext classes in the project...
Using context 'MyAppUserDbContext'.
info: Microsoft.EntityFrameworkCore.Infrastructure[10403]
Entity Framework Core 2.0.2-rtm-10011 initialized 'MyAppUserDbContext' using provider 'Microsoft.EntityFrameworkCore.SqlServer' with options: MigrationsAssembly=MyApp.Core.dll
Finding design-time services for provider 'Microsoft.EntityFrameworkCore.SqlServer'...
Using design-time services from provider 'Microsoft.EntityFrameworkCore.SqlServer'.
Finding IDesignTimeServices implementations in assembly 'MyAppApp.Web'...
No design-time services were found.
System.IO.FileNotFoundException: Could not load file or assembly 'MyApp.Core.dll, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.
我试过的选项我没有成功:
.dll
文件复制到.Web
文件夹(启动)dotnet restore
思考 - 我没有沿着实现IDesignTimeDbContextFactory
的道路走下去,因为我认为它不是必需的,因为我可以设置启动并且它引用了libs。
我觉得有用的链接 - Sample project和Microsoft documentation