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

-Environment argument removed from Update migration command and ASPNETCORE_ENVIRONMENT ignored #9623

Closed
ihandley opened this issue Aug 30, 2017 · 7 comments
Labels
closed-no-further-action The issue is closed and no further action is planned.

Comments

@ihandley
Copy link

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

@ajcvickers
Copy link
Contributor

ajcvickers commented Aug 30, 2017

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

$env:ASPNETCORE_ENVIRONMENT="Staging"

@ajcvickers ajcvickers added the closed-no-further-action The issue is closed and no further action is planned. label Aug 30, 2017
@ihandley
Copy link
Author

I have tried this. No dice.

@ajcvickers ajcvickers reopened this Aug 31, 2017
@moraleslos
Copy link

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

@ajcvickers
Copy link
Contributor

@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?

@ihandley
Copy link
Author

ihandley commented Sep 5, 2017

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?

@bricelam
Copy link
Contributor

bricelam commented Sep 5, 2017

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.

@theBoringCoder
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-no-further-action The issue is closed and no further action is planned.
Projects
None yet
Development

No branches or pull requests

5 participants