Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrations: CLI Tools: Honor ASPNETCORE_ENVIRONMENT #7353

Closed
Eilon opened this issue Jan 5, 2017 · 13 comments
Closed

Migrations: CLI Tools: Honor ASPNETCORE_ENVIRONMENT #7353

Eilon opened this issue Jan 5, 2017 · 13 comments
Assignees
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-enhancement
Milestone

Comments

@Eilon
Copy link
Member

Eilon commented Jan 5, 2017

From @opensrcken on November 2, 2016 7:57

Representative of the script I'm using when I encounter said bug.

SET ASPNETCORE_ENVIRONMENT=Test
dotnet ef database update

env.EnvironmentName does not not seem to be aware of ASPNETCORE_ENVIRONMENT when running the second command. Instead, it is always set to Development.

Copied from original issue: dotnet/core#327

@Eilon
Copy link
Member Author

Eilon commented Jan 5, 2017

From @Petermarcu on January 5, 2017 0:51

@Eilon , Where's the best place to track this?

@Eilon
Copy link
Member Author

Eilon commented Jan 5, 2017

Bug might not be in EF, but at least we should start the investigation here.

@mgolois
Copy link

mgolois commented Jan 5, 2017

did you try using "Setx" instead of "Set"?
http://batcheero.blogspot.com/2008/02/set-and-setx.html

@bricelam
Copy link
Contributor

bricelam commented Jan 5, 2017

We don't currently honor the ASPNETCORE_ENVIRONMENT environment variable. You should be able to get it working by using the following.

dotnet ef database update --environment %ASPNETCORE_ENVIRONMENT%

@Eilon
Copy link
Member Author

Eilon commented Jan 5, 2017

@bricelam should we add support for that env var? It's a bit gross to tie the two together, but it's also a very common scenario to use EF in ASP.NET.

@bricelam
Copy link
Contributor

bricelam commented Jan 5, 2017

We should definitely consider it.

@Eilon
Copy link
Member Author

Eilon commented Jan 5, 2017

I love definite maybes! 😄

@divega divega added this to the 2.0.0 milestone Jan 9, 2017
@bricelam bricelam added the tools label Jan 11, 2017
@bricelam bricelam changed the title Potential bug: Setting ASPNETCORE_ENVIRONMENT from the command line does not seem to work CLI Tools: Honor ASPNETCORE_ENVIRONMENT Feb 27, 2017
@ajcvickers ajcvickers modified the milestones: 2.0.0-preview1, 2.0.0 Apr 19, 2017
@bricelam bricelam removed the tools label Apr 26, 2017
@bricelam bricelam added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Apr 27, 2017
@bricelam bricelam modified the milestones: 2.0.0-preview1, 2.0.0 Apr 27, 2017
@ajcvickers ajcvickers changed the title CLI Tools: Honor ASPNETCORE_ENVIRONMENT Migrations: CLI Tools: Honor ASPNETCORE_ENVIRONMENT May 9, 2017
@univhack
Copy link

Any plans to address this and start taking into account ASPNETCORE_ENVIRONMENT by any chance? The EF Core docs recommend setting this env variable which is a bit confusing since it's not being used (see tip green box

@bricelam
Copy link
Contributor

It has worked since version 2.0.0-preview1. Note, if you're using PowerShell, the syntax to set an environment variable is different than command prompt:

$env:ASPNETCORE_ENVIRONMENT = 'Production'

@univhack
Copy link

That's great news thanks for the update @bricelam!

@mrtgr
Copy link

mrtgr commented May 31, 2018

I'm writing $env:ASPNETCORE_ENVIRONMENT = 'Production' in Package Manager Console and then running Update-Database but still gives the same warning "No Migrations were applied". It is still not respecting to my ASPNETCORE_ENVIRONMENT.

@ajcvickers
Copy link
Contributor

@mrtgr Can you please file a new issue and include a runnable project/solution that demonstrates the behavior you are seeing?

@ghost
Copy link

ghost commented Jul 3, 2019

I have recently had a problem with EF tool not using connection strings from my "appsettings.Production" file, it Turns out that if EF Tool has trouble with the "appsettings.Production"(E.g null string) , it will revert to using appsettings. I have not been able to see this written to the console by the EF tool, but using the "-verbose" flag with database update, the environment will be written to the console. Just wanted to mention this as I have not seen this documented anywhere.

@ajcvickers ajcvickers modified the milestones: 2.0.0-preview1, 2.0.0 Oct 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-enhancement
Projects
None yet
Development

No branches or pull requests

7 participants