MichaelMao
MichaelMao

Reputation: 2796

ASP.NET Core publish with different env appsetting

Now I using dnu restore, dnu build and dnu publish -o {outputpath} to publish my ASP.NET Core website. I have appsettings.json and appsettings.STG.json how can I publish with different appsetting just like web.config before? I see some discuss on SO is use enviromentVariables but is this a good way?

Upvotes: 2

Views: 782

Answers (1)

Dmitry
Dmitry

Reputation: 16795

ASP.Net 5/Core can use choose/combine different appsettings.json files during startup based on environment variables or other criteria you wish. But you can't "merge" different files into physical one (without any external tasks/tools).

Is this a "good" or "bad" way - completely depends on your scenario.

For storing connection strings (and other secrets) for dev/prod in different files this definitely a BAD idea, because you will store your production secrets in source code. Instead, use AddEnvironmentVariables and override you dev param values with production one "inside" production server.

Upvotes: 3

Related Questions