Efcore: -Environment argument removed from Update migration command and ASPNETCORE_ENVIRONMENT ignored

Created on 30 Aug 2017  路  7Comments  路  Source: dotnet/efcore

I am simply unable to do a migration to my staging environment.

From what I've read here, the environment argument was removed and we should now be able to use the ASPNETCORE_ENVIRONMENT environment variable to target environments other than development. I recognize those docs may not be current, but I have been unable to find anything else relevant to my issue anywhere else. I've tried using the CLI and the PMC with the same result.

This is the first part of what I'm seeing when I run Update-Database in the PMC:

PM> Update-Database -verbose
Using project 'ICv2.Data'.
Using startup project 'ICv2.Api'.
Build started...
Build succeeded.
C:\Program Files\dotnet\dotnet.exe exec --depsfile C:\Users\Ihandley\Source\Repos\ICv2\ICv2.Api\bin\Debug\netcoreapp2.0\ICv2.Api.deps.json --additionalprobingpath C:\Users\Ihandley\.nuget\packages --additionalprobingpath "C:\Program Files\dotnet\sdk\NuGetFallbackFolder" --runtimeconfig C:\Users\Ihandley\Source\Repos\ICv2\ICv2.Api\bin\Debug\netcoreapp2.0\ICv2.Api.runtimeconfig.json "C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.entityframeworkcore.tools\2.0.0\tools\netcoreapp2.0\ef.dll" database update --verbose --no-color --prefix-output --assembly C:\Users\Ihandley\Source\Repos\ICv2\ICv2.Api\bin\Debug\netcoreapp2.0\ICv2.Data.dll --startup-assembly C:\Users\Ihandley\Source\Repos\ICv2\ICv2.Api\bin\Debug\netcoreapp2.0\ICv2.Api.dll --project-dir C:\Users\Ihandley\Source\Repos\ICv2\ICv2.Data --root-namespace ICv2.Data
Using assembly 'ICv2.Data'.
Using startup assembly 'ICv2.Api'.
Using application base 'C:\Users\Ihandley\Source\Repos\ICv2\ICv2.Api\bin\Debug\netcoreapp2.0'.
Using working directory 'C:\Users\Ihandley\Source\Repos\ICv2\ICv2.Api'.
Using root namespace 'ICv2.Data'.
Using project directory 'C:\Users\Ihandley\Source\Repos\ICv2\ICv2.Data'.
Finding DbContext classes...
Finding IDesignTimeDbContextFactory implementations...
Finding application service provider...
Finding BuildWebHost method...
Using environment 'Development'.
Using application service provider from BuildWebHost method on 'Program'.

Notice the Using environment 'Development'. bit even though I have my ASPNETCORE_ENVIRONMENT environment variable set to Staging.

Further technical details

EF Core version: 2.0.0
Database Provider: Microsoft.EntityFrameworkCore.SqlServer
Operating system:
IDE: Visual Studio 2017

closed-question

Most helpful comment

The old way (using the -e switch) was far superior for those of supporting multiple runtime environments for our apps.

All 7 comments

@ihandley Make sure that the environment variable is set correctly in PowerShell. Something like,

$env:ASPNETCORE_ENVIRONMENT="Staging"

I have tried this. No dice.

It works for me, although I preferred the older way: #9664

@ihandley Can you run

get-childitem env:

in the PMC after setting the environment but before running the migration command and check that the environment variable is set? If so and this is still not working then are you doing anything different/unusual in the PMC window? Would it be possible to attach a project where this happens so we can debug?

Well that's strange. Last week I when I was setting the environmental variable as you first suggested, it didn't appear to have any effect on my migration commands. However, this morning I tried it and it worked! The ol' car at the mechanic phenomenon.

It still seems like setting the environmental variable in the project properties isn't being recognized. Is that a known issue? Is the only way of switching environments at this point to do it manually in the CLI or PMC?

Correct. Hosting reads the environment variable during startup. While environment variables can be read using project properties, the opposite is not true--project properties aren't exported to environment variables.

The old way (using the -e switch) was far superior for those of supporting multiple runtime environments for our apps.

Was this page helpful?
0 / 5 - 0 ratings