Deploying Dotnet Core Entity framework migrations

.net-core entity-framework-core octopus-deploy

Question

I am working on a fresh .netcore api project. I am trying to deploy the application using octopus.

I need help on executing the migrations from command line and I am not getting a lot of help. If some one can help me it will really help.

Here is what I have tried so far: I have taken help of the following link to come up with a solution but it does not really work for me.

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

I had to make few modifications to the script in order to set the dll paths right. Here is how it is looking now

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%

However the script throws index oput of bound error which is very confusing to me. Here is the exception.

System.IndexOutOfRangeException: Index was outside the bounds of the array. at Microsoft.DotNet.Cli.CommandLine.CommandLineApplication.ParseOption(Boolean isLongOption, CommandLineApplication c ommand, String[] args, Int32& index, CommandOption& option) at Microsoft.DotNet.Cli.CommandLine.CommandLineApplication.Execute(String[] args) at Microsoft.EntityFrameworkCore.Tools.Program.Main(String[] args) Index was outside the bounds of the array.

Any clue to this error? Or if I should take any other approach?

1
1
6/13/2017 9:58:28 PM

Accepted Answer

It seems that the dotnet exec command is not build correctly, seeing as it has problems parsing your commands.

I'm using dotnet core 2-preview and had to change the batch file slightly. I now works for me:

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%
1
8/10/2017 9:34:21 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow