2017-06-13 46 views
0

我正在創建一個新的.netcore api項目。我正在嘗試使用章魚來部署應用程序。部署Dotnet Core Entity框架遷移

我需要從命令行執行遷移的幫助,我沒有得到很多幫助。如果有人能幫助我,那真的會有幫助。

以下是我到目前爲止所嘗試的: 我已經採取了以下鏈接的幫助來提出解決方案,但它並不適合我。

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% 

但是腳本拋出界的錯誤,這是非常混亂,我的指數oput。這是例外。

System.IndexOutOfRangeException:索引超出了數組的範圍。 在Microsoft.DotNet.Cli.CommandLine.CommandLineApplication.ParseOption(布爾isLongOption,CommandLineApplicationÇ ommand,字串[] args,的Int32 &指數,CommandOption &選項) 在Microsoft.DotNet.Cli.CommandLine.CommandLineApplication.Execute(字符串[] args) at Microsoft.EntityFrameworkCore.Tools.Program.Main(String [] args) 索引超出了數組的範圍。

這個錯誤的任何線索?或者如果我應該採取其他方法?

回答

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% 
+0

這當然適用於我。我認爲我遇到的問題是在部署到服務器時使用此腳本。 PathToNuGetPackages和PathToEfDll值在不同的服務器或環境中可能會有所不同。 .nu​​get文件夾當然不適用於我使用neer的werver 2012,任何2.0包都部署在我的配置文件下。 –