简体   繁体   中英

Using a web.config file in .Net Core Web API

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

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM