Reputation: 429
FACTS:
different appsettings.json file for different environments
I utilize Package Manager Console to generate my DB scripts (Add-Migration, Update-Database)
If I run PM>"Get-DbContext" it brings back info pulled from my appsettings.Development.json file GREAT, that's what I want most of the time!
But how do I tell it to pull db variables from appsettings.Staging.json instead of development for PM commands?
I tried creating new launchSettings.json profiles and setting "ASPNETCORE_ENVIRONMENT": "Staging" but everything seems to respect that except PM.
PS work around it to generate script with Script-Migration but I would like the fast UP and DOWN I get and wont use it to deploy to prod
Upvotes: 4
Views: 6166
Reputation: 429
Not well documented but you can have to changed the ASPNETCORE_ENVIRONMENT manually by running this command in Package Manager Console
PM> $env:ASPNETCORE_ENVIRONMENT='Staging'
then you can run this command to verify it is pointing to your desired database:
PM> Get-DbContext
which will kick out
providerName databaseName dataSource options
------------ ------------ ---------- -------
Microsoft.EntityFrameworkCore.SqlServer myDatabase tcp:fake.database.windows.net,1433 None
then just run your commands as normal. Example:
Update-Database
Reference to commands: https://learn.microsoft.com/en-us/ef/core/miscellaneous/cli/powershell
Upvotes: 14