Skip to content

Running EF Core Migrations from DLLs on Linux #13339

Closed as not planned
Closed as not planned

Description

@mmillican

I'm currently working on setting up a build to our Linux EC2 instances via Code Deploy and have been having some issues getting EF Migrations to run.

Running dotnet ef database update -p ProjectName.Backend.Core.dll -s ProjectName.Backend.Api.dll produces the following:

/path_to/MyProject.Backend.Core.dll(1,1): error MSB4025: The project file could not be loaded. Data at the root level is invalid. Line 1, position 1.
Unable to retrieve project metadata. Ensure it's an MSBuild-based .NET Core project. If you're using custom BaseIntermediateOutputPath or MSBuildProjectExtensionsPath values, Use the --msbuildprojectextensionspath option.

What do I need to get migrations to run on Linux from a published output?

I've seen Ben Day's post about deploying from DLLs for EF Core 2.1, but this is for more of a Windows environment (both the batch script and file locations).

Activity

  1. ajcvickers commented on Sep 17, 2018

    @ajcvickers
    Contributor

    @mmillican The concept should be the same as is described in the post. Are you asking for help converting the script to run in your Linux shell?

  2. mmillican commented on Sep 18, 2018

    @mmillican
    Author

    @ajcvickers I can probably convert the script (at least the basics) if someone hasn't already.

    My other question though is: how do I get the EF tools installed on the instance? EF isn't available as a global tool and these instances wouldn't have the Nuget packages installed on them.

  3. smitpatel commented on Sep 18, 2018

    @smitpatel
    Contributor

    From the blog post

    One of the hardest parts of scripting this is trying to figure out where ef.dll is on disk. The script tries to find ef.dll in a couple different places but if it can’t find it, the script will fail. If you don’t want to deal with that uncertainty, you can now just manually put ef.dll into the same directory as the script and the script will use that copy.

    That's it. Just copy over ef.dll file on your instance (probably alongwith the script) and use it directly.

  4. mmillican commented on Sep 19, 2018

    @mmillican
    Author

    [Edited as I finally found the ef.dll file]

    Are there any plans for making this easier in the future? This is incredibly frustrating and annoying.

  5. ajcvickers commented on Sep 20, 2018

    @ajcvickers
    Contributor

    @benday Do you have anything describing more specifically how to do this on Linux, or would you consider adding it to your post?

  6. mmillican commented on Sep 20, 2018

    @mmillican
    Author

    @ajcvickers @benday I ended up figuring this out yesterday and plan on doing a blog post soon.

    Would be great to have this support built in.

  7. bricelam commented on Sep 20, 2018

    @bricelam
    Contributor

    Note, the easiest way to get the command to run is to use dotnet ef database update --verbose and look for a line that starts like this:

    dotnet exec --depsfile MyApp.deps.json --runtimeconfig MyApp.runtimeconfig.json ef.dll database update
    
  8. benday commented on Sep 21, 2018

    @benday

    @benday Do you have anything describing more specifically how to do this on Linux, or would you consider adding it to your post?

    @ajcvickers, I'd be happy to share more info about doing migration deploys with Linux. How can I help? What do you think is missing? What are you finding difficult and/or confusing?

  9. jcmiron commented on Sep 25, 2018

    @jcmiron

    I'm having the same issue, @mmillican did you create the blogpost yet?

  10. mmillican commented on Sep 27, 2018

    @mmillican
    Author

    @jcmiron I'm hoping to have it ready this weekend.

  11. scottaddie commented on Sep 27, 2018

    @scottaddie
    Member

    @livarcocc @TheRealPiotrP Issue https://github.com/dotnet/cli/issues/2243 discouraged the use of dotnet exec. See Brice's comment above. Is this a case where exec absolutely must be used. I'm asking from a documentation perspective. If there are edge cases like this, maybe we should add a note to the CLI docs.

  12. bricelam commented on Sep 28, 2018

    @bricelam
    Contributor

    Is this a case where exec absolutely must be used.

    Yep. Don't try this at home, folks. It's dangerous, but we know what we're doing. .NET CLI team supervision is required. 😉

  13. mmillican commented on Sep 28, 2018

    @mmillican
    Author

    Don't try this at home

    So can I publish it in a blog post?

  14. bricelam commented on Sep 28, 2018

    @bricelam
    Contributor

    The dirty details: We're effectively running ef.dll as if it was your app. We use your app's dependencies and your app's runtime config. If you're not careful you can run into missing or conflicting assemblies.

    But yes, it's safe to run the command you see in --verbose. This is exactly what calling dotnet ef runs behind the scenes.

  15. livarcocc commented on Sep 28, 2018

    @livarcocc

    @bricelam you are giving away all our secrets man.

    @scottaddie I am not sure this warrants document this or not. This is actually part of the host itself and not really the CLI, so I will let @jeffschwMSFT comment on it.

  16. bricelam commented on Sep 28, 2018

    @bricelam
    Contributor

    So can I publish it in a blog post?

    Absolutely. ef.dll was designed to be called with dotnet exec

  17. bricelam commented on Sep 28, 2018

    @bricelam
    Contributor

    @scottaddie I wouldn't mention it in the docs. This is just implementation detail of the dotnet ef command. The blog post documents the manual steps you have to take for a super advanced scenario: Running EF Core migrations without the .NET Core SDK or your *.csproj file available.

  18. bricelam commented on Sep 28, 2018

    @bricelam
    Contributor

    Note, our recommended approach is to generate SQL script on the dev box and run those on the server instead. At least until we have a good delivery mechanism for an EF tool that can run directly against assemblies.

  19. mmillican commented on Sep 28, 2018

    @mmillican
    Author

    Thanks for the feedback @bricelam, @scottaddie and @livarcocc. Currently trying to update the post I have to mention these recommendations.

  20. mmillican commented on Sep 28, 2018

    @mmillican
    Author

    The blog post has been published. If the team has any feedback, please let me know.

    Thanks for the help all!

    cc @jcmiron

  21. ajcvickers commented on Oct 1, 2018

    @ajcvickers
    Contributor

    Thanks everyone for your input and contributions here. I'm closing this out now in favor of some remaining follow-up items on the relevant docs issue: dotnet/EntityFramework.Docs#807

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions