Skip to content

Show how to use ASPNETCORE_ENVIRONMENT with Migrations #1050

Closed

Description

@cni13

The mentioned section misses to explain some (for me) important details you need if you want to use this approach:
The call Program.BuildWebHost is implicitly called with an ASPNETCORE_ENVIRONMENT setting of "development". That means that if you read the connection string from e.g. the appsettings inside AddDbContext, you need to have an appsettings file for this environment variable. Otherwise the root appsettings will be used, which means that you have to also copy the connection string to the database you want to use to this file. Otherwise this approach will fail, because it cant find the connection string.
Also in general the application needs to be able to start with the "development" env variable. If it for some reason does not build, you might face exceptions that you can't associate with the source of the problem.

My proposal:

  • Further explain the behavior of the mentioned section, including the implicit usage of "development" as env var
  • Perhaps give a short example on how to use this approach in practice

Document Details

⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

Activity

  1. changed the title [-]Expand the section "From application services"[/-] [+]Show how to use ASPNETCORE_ENVIRONMENT with Migrations[/+] on Aug 29, 2019
  2. added this to the Backlog milestone on Sep 2, 2019
  3. modified the milestones: Backlog, 3.1.0 on Sep 6, 2019
  4. modified the milestones: 3.1.0, 5.0.0 on Jan 15, 2020
  5. bricelam commented on Aug 25, 2020

    @bricelam
    Contributor

    Note to documenter: Mention DOTNET_ENVIRONMENT too

  6. Rick-Anderson commented on Sep 17, 2020

    @Rick-Anderson
    Contributor
  7. bricelam commented on Sep 22, 2020

    @bricelam
    Contributor

    Note, in EF Core 5.0, you can pass it into the host builder via an argument without having to set the environment variable:

    dotnet ef database update -- --environment Production
    
  8. added 2 commits that reference this issue on Oct 27, 2020
    ee417b2
    41f3772
  9. added 5 commits that reference this issue on Oct 28, 2020
    793307d
    040b9a3
    b00355e
    993c565
    f0f6905
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions