部署 Dotnet Core Entity framework 迁移

Deploying Dotnet Core Entity framework migrations

我正在开发一个新的 .netcore api 项目。我正在尝试使用章鱼部署应用程序。

我需要有关从命令行执行迁移的帮助,但我没有得到很多帮助。如果有人能帮助我,那真的很有帮助。

这是我目前尝试过的方法: 我在以下 link 的帮助下提出了一个解决方案,但它对我来说并不奏效。

https://www.benday.com/2017/03/17/deploy-entity-framework-core-migrations-from-a-dll/

为了正确设置 dll 路径,我不得不对脚本进行少量修改。 这是现在的样子

set EfMigrationsNamespace=%Dummy.WebAPI 
set EfMigrationsDllName=%Dummy.WebAPI.deps.dll 
set EfMigrationsDllDepsJson=%Dummy.WebAPI.deps.json 
set EfMigrationsStartupAssembly=%Dummy.Data.dll 
set DllDir=%cd% 
set PathToNuGetPackages=%USERPROFILE%\.nuget\packages 
set PathToEfDll=%PathToNuGetPackages%\microsoft.entityframeworkcore.tools.1.1\tools\netcoreapp1.0\ef.dll
ECHO %PathToEfDll%

dotnet exec --depsfile .\%EfMigrationsDllDepsJson% --additionalprobingpath %PathToNuGetPackages% %PathToEfDll% database update --assembly .\%EfMigrationsDllName% --startup-assembly .\%EfMigrationsStartupAssembly% --project-dir . --content-root %DllDir% --data-dir %DllDir% --verbose --root-namespace %EfMigrationsNamespace%

但是脚本抛出绑定错误的索引输入,这让我很困惑。这里是例外。

System.IndexOutOfRangeException: 索引超出数组范围。 在 Microsoft.DotNet.Cli.CommandLine.CommandLineApplication.ParseOption(Boolean isLongOption, CommandLineApplication c 命令、String[] args、Int32& 索引、CommandOption& 选项) 在 Microsoft.DotNet.Cli.CommandLine.CommandLineApplication.Execute(字符串 [] 参数) 在 Microsoft.EntityFrameworkCore.Tools.Program.Main(字符串[] 参数) 索引超出数组范围。

这个错误有什么线索吗?或者我是否应该采取任何其他方法?

似乎 dotnet exec 命令构建不正确,因为它在解析您的命令时出现问题。

我正在使用 dotnet core 2-preview 并且不得不稍微更改批处理文件。我现在为我工作:

set EfMigrationsNamespace=%1
set EfMigrationsDllName=%1.dll
set EfMigrationsDllDepsJson=%1.deps.json
set DllDir=%cd%
set PathToNuGetPackages=%USERPROFILE%\.nuget\packages
set PathToEfDll=%PathToNuGetPackages%\microsoft.entityframeworkcore.tools.0.0-preview2-final\tools\netcoreapp2.0\ef.dll

dotnet exec --depsfile .\%EfMigrationsDllDepsJson% --additionalprobingpath %PathToNuGetPackages% %PathToEfDll% database update --assembly .\%EfMigrationsDllName% --startup-assembly .\%EfMigrationsDllName% --project-dir . --data-dir %DllDir% --verbose --root-namespace %EfMigrationsNamespace%