1

We're building a .net core web api application at the moment and so far it's been great to work with. However we have an issue with our deployment server (Team Studio) being unable to replace the DB connection string inside the appsettings.json file. Is it possible to solve this issue by putting the connection string in the old web.config format so that Team Services can do a replacement? I tried creating one but I'm unable to access the connection string from it using System.Configuration

2

2 Answers 2

4

The way appsettings.json is supposed to work is that it should only contain environment-neutral config. Anything specific to a particular environment, such as connection strings, should go into appsettings.{Environment}.json. That file is then loaded in based on the ASPNETCORE_ENVIRONMENT environment variable set on the server you're deploying to. In other words, you shouldn't need to replace anything. Just deploy both appsettings.json and appsettings.{Environment}.json and make sure that the ASPNETCORE_ENVIRONMENT variable is set appropriately.

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

2 Comments

That would require any passwords or sensitive data to be checked in to the source repository. Substitution allows for a second layer of security, which is why I prefer to use substitution of appsettings.json in the release pipeline of VSTS. It works great there, but won’t help in this case unfortunately.
That's where an externalized config provider would come into play. You can set the connection using environment variable on the server or use something like Azure Key Vault.
0

Fortunately, web.config was removed from .net core. Only one thing that I can recommend is to create power shell script that will replace connection strings in your appsettings.json, and call it using team city agent.

Comments

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.