[英]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. 目前,我们正在构建.net核心Web api应用程序,到目前为止,使用它非常好。 However we have an issue with our deployment server (Team Studio) being unable to replace the DB connection string inside the appsettings.json file.
但是,我们的部署服务器(Team Studio)无法替换appsettings.json文件中的数据库连接字符串,这是一个问题。 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?
是否可以通过将连接字符串设置为旧的web.config格式来解决此问题,以便Team Services可以进行替换? I tried creating one but I'm unable to access the connection string from it using System.Configuration
我尝试创建一个,但是无法使用System.Configuration从中访问连接字符串
The way appsettings.json
is supposed to work is that it should only contain environment-neutral config. appsettings.json
应该起作用的方式是,它只应包含与环境appsettings.json
配置。 Anything specific to a particular environment, such as connection strings, should go into appsettings.{Environment}.json
. 特定于特定环境的任何内容(例如连接字符串)都应放入
appsettings.{Environment}.json
。 That file is then loaded in based on the ASPNETCORE_ENVIRONMENT
environment variable set on the server you're deploying to. 然后,根据要部署到的服务器上设置的
ASPNETCORE_ENVIRONMENT
环境变量加载该文件。 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. 只需部署
appsettings.json
和appsettings.{Environment}.json
appsettings.json
并确保ASPNETCORE_ENVIRONMENT
设置了ASPNETCORE_ENVIRONMENT
变量。
Fortunately, web.config was removed from .net core. 幸运的是,web.config已从.net核心中删除。 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.
我只能推荐的一件事就是创建Power Shell脚本,该脚本将替换appsettings.json中的连接字符串,并使用Team City Agent进行调用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.