2

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?

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

5 Comments

Thx. I just want to check does there are other ways to do that in asp.net 5. I do not know how to do what you say "use AddEnvironmentVariables and override you dev param value..." but I will survey that. Thank you!
Here you can find best practices for running in Azure. If you are deploying it to Azure.
docs.asp.net/en/latest/fundamentals/… is good start. Env. variables are very handy in clouds (like Azure), where you have no direct/easy access to host OS and servers are managed/restarted automatically. For on-premises deployments separate settings file (stored only on your server, not in source code) are more manageable.
But it didn't says hot to set EnvironmentVariables
For storing connection strings and secrets you should consider UserSecrets github.com/aspnet/usersecrets

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.