我有一个名为项目MyApp
包含实体框架的核心模式。为了从这些模型创建初始数据库,我在Visual Studio的Package Manager控制台中使用了以下命令:
dotnet ef migrations -v add InitialCreate
我的项目的目录结构是这样的:
MyApp
|-bin
| |-Debug
| | |-netcoreapp2.1
| | | |-bin
. . . | |-...
. . . | |-MyApp.dll
. . . | |-...
|-MyApp.deps.json
|-MyApp.runtimeconfig.dev.json
|-MyApp.runtimeconfig.json
当我运行以上命令创建初始数据库时,弹出以下错误:
An assembly specified in the application dependencies manifest
(MyApp.deps.json) was not found:
package: 'MyApp', version: '1.0.0'
path: 'MyApp.dll'
因此,该命令无法找到目录MyApp.dll
中的bin
文件。
从以下详细输出中可以清楚地看出:
PM> dotnet ef migrations -v add InitialCreate
Using project 'C:\Users\rohan\Projects\MySolution\myproject\MyApp.csproj'.
Using startup project 'C:\Users\rohan\Projects\MySolution\myproject\MyApp.csproj'.
Writing 'C:\Users\rohan\Projects\MySolution\myproject\obj\MyApp.csproj.EntityFrameworkCore.targets'...
dotnet msbuild /target:GetEFProjectMetadata /property:EFProjectMetadataFile=C:\Users\rohan\AppData\Local\Temp\tmp4BF.tmp /verbosity:quiet /nologo C:\Users\rohan\Projects\MySolution\myproject\MyApp.csproj
Writing 'C:\Users\rohan\Projects\MySolution\myproject\obj\MyApp.csproj.EntityFrameworkCore.targets'...
dotnet msbuild /target:GetEFProjectMetadata /property:EFProjectMetadataFile=C:\Users\rohan\AppData\Local\Temp\tmpEB2.tmp /verbosity:quiet /nologo C:\Users\rohan\Projects\MySolution\myproject\MyApp.csproj
dotnet build C:\Users\rohan\Projects\MySolution\myproject\MyApp.csproj /verbosity:quiet /nologo
Build succeeded.
0 Warning(s)
0 Error(s)
Time Elapsed 00:00:17.49
dotnet exec --depsfile C:\Users\rohan\Projects\MySolution\myproject\bin\Debug\netcoreapp2.1\MyApp.deps.json
--additionalprobingpath C:\Users\rohan\.nuget\packages --additionalprobingpath "C:\Program Files\dotnet\sdk\NuGetFallbackFolder"
--runtimeconfig C:\Users\rohan\Projects\MySolution\myproject\bin\Debug\netcoreapp2.1\MyApp.runtimeconfig.json
"C:\Program Files\dotnet\sdk\2.1.700\DotnetTools\dotnet-ef\2.1.11\tools\netcoreapp2.1\any\tools\netcoreapp2.0\any\ef.dll"
migrations add InitialCreate
--assembly C:\Users\rohan\Projects\MySolution\myproject\bin\Debug\netcoreapp2.1\MyApp.dll
--startup-assembly C:\Users\rohan\Projects\MySolution\myproject\bin\Debug\netcoreapp2.1\MyApp.dll
--project-dir C:\Users\rohan\Projects\MySolution\myproject\ --language C#
--working-dir C:\Users\rohan\Projects\MySolution\myproject --verbose --root-namespace MyApp
dotnet : Error:
At line:1 char:1
+ dotnet ef migrations -v add InitialCreate
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (Error::String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
An assembly specified in the application dependencies manifest (MyApp.deps.json) was not found:
package: 'MyApp', version: '1.0.0'
path: 'MyApp.dll'
基本上,该dll
文件的路径--assembly
和--startup-assembly
选项是不正确的。这是因为(通过上述命令)生成的MyApp.deps.json
包含以下内容:
{
"runtimeTarget": {
"name": ".NETCoreApp,Version=v2.1",
"signature": "..."
},
"compilationOptions": {},
"targets": {
".NETCoreApp,Version=v2.1": {
"MyApp/1.0.0": {
"dependencies": {
...
},
"runtime": {
"MyApp.dll": {}
}
},
...
}
...
}
...
}
在这里,的runtime
JSON对象中MyApp/1.0.0
包含文件的相对路径,dll
MyApp.dll
而应该是bin/MyApp.dll
。
我应该怎么做才能在runtime
JSON对象中写入正确的路径?
我有一个非常相似的问题。经过数小时的搜索和实验,我发现了这篇文章:https : //github.com/aspnet/EntityFrameworkCore/issues/14679
将数据库内容分离到一个单独的类库项目中,然后添加IDesignTimeDbContextFactory为我修复了它。
祝好运
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句