Is there a way to run EF Core RC2 tools from published DLL?

后端 未结 5 1830
抹茶落季
抹茶落季 2021-02-07 03:26

After publishing a .Net Core RC1 application, commands specified in the project.json had corresponding .cmd files created for them which could be executed after deployment (e.g.

5条回答
  •  旧巷少年郎
    2021-02-07 03:51

    There is an extremely useful post with a solution to this problem here.

    It worked for me (I had to tweak the commands a little bit, but it gave me a good basis to start).

    In sum: you can replicate the dotnet ef database update command by passing the ef.dll (e.g. directly from your nuget folder (or from somewhere else if you don’t have nuget, since you are on a prod machine..)) with your .dll containing the migrations with some additional parameters (see below) to dotnet.exe (or the linux equivalent).

    For completeness here is the .cmd (also from the blogpost!)

    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.dotnet\1.0.0\tools\netcoreapp1.0\ef.dll
    
    dotnet exec --depsfile .\%EfMigrationsDllDepsJson% --additionalprobingpath %PathToNuGetPackages% %PathToEfDll% database update --assembly .\%EfMigrationsDllName% --startup-assembly .\%EfMigrationsDllName% --project-dir . --content-root %DllDir% --data-dir %DllDir% --verbose --root-namespace %EfMigrationsNamespace%
    

    (A bash version if this cmd is in the blogpost)

    Btw. this approach was also mentioned in many github issues: https://github.com/aspnet/EntityFramework.Docs/issues/328 https://github.com/aspnet/EntityFramework.Docs/issues/180

    ps: I found this in the blog of Ben Day, so all credit goes to Ben!

提交回复
热议问题