【问题标题】:Deploying Dotnet Core Entity framework migrations部署 Dotnet Core Entity 框架迁移
【发布时间】:2017-06-13 21:58:28
【问题描述】:

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

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

这是我迄今为止尝试过的: 我已经通过以下链接提出了解决方案,但它对我来说并不适用。

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.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(布尔 isLongOption,CommandLineApplication c 命令,String[] args,Int32& 索引,CommandOption& 选项) 在 Microsoft.DotNet.Cli.CommandLine.CommandLineApplication.Execute(String[] args) 在 Microsoft.EntityFrameworkCore.Tools.Program.Main(String[] args) 索引超出了数组的范围。

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

【问题讨论】:

    标签: .net-core entity-framework-core octopus-deploy


    【解决方案1】:

    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\2.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%
    

    【讨论】:

    • 这当然对我有用。我认为我遇到的问题是在部署到服务器时使用此脚本。 PathToNuGetPackages 和 PathToEfDll 值在不同的服务器或环境中可能不同。 .nu​​get 文件夹在我使用的 werver 2012 中肯定不可用,我的配置文件下部署了任何 2.0 包。
    猜你喜欢
    • 1970-01-01
    • 2019-03-06
    • 2017-10-27
    • 2018-04-05
    • 2017-05-16
    • 2018-11-05
    • 2020-03-09
    • 2017-02-06
    • 1970-01-01
    相关资源
    最近更新 更多