_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_
_From @Petermarcu on January 5, 2017 0:51_
@Eilon , Where's the best place to track this?
Bug might not be in EF, but at least we should start the investigation here.
did you try using "Setx" instead of "Set"?
http://batcheero.blogspot.com/2008/02/set-and-setx.html
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%
@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.
We should definitely consider it.
I love definite maybes! 馃槃
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
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'
That's great news thanks for the update @bricelam!
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.
@mrtgr Can you please file a new issue and include a runnable project/solution that demonstrates the behavior you are seeing?
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.
Most helpful comment
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.