参考:数据库
ASP.NET Core 中的配置windows
在项目的 Properties\launchSettings.json中能够配置多个环境api
{ "iisSettings": { "windowsAuthentication": false, "anonymousAuthentication": true, "iisExpress": { "applicationUrl": "http://localhost:49716/", "sslPort": 0 } }, "profiles": { "IIS Express": { "commandName": "IISExpress", "launchBrowser": true, "launchUrl": "api/values", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } }, "ApiCenter": { "commandName": "Project", "launchBrowser": true, "launchUrl": "api/values", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" }, "applicationUrl": "http://localhost:5001/" }, "ApiCenter-Test": { "commandName": "Project", "launchBrowser": true, "launchUrl": "api/values", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Staging" }, "applicationUrl": "http://localhost:5002/" }, "ApiCenter-Production": { "commandName": "Project", "launchBrowser": true, "launchUrl": "api/values", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Production" }, "applicationUrl": "http://localhost:5003/" } } }
在VS调试的时候能够选择使用哪一个app
对应的appsetting.jsonide
这样就能够在不一样的环境使用不一样的配置post
cmd中执行ui
set ASPNETCORE_ENVIRONMENT=Development
这个只对当前cmd窗口有效,关闭后就失效了,要永久修改的话能够设置环境变量spa
使用export 或者永久修改/etc/profile调试
接下来在发布目录执行就会使用配置的环境了
固然若是在源码目录执行的话只会使用第一个配置
把上面两个注释再执行
如原来的数据库配置地址以下
"ConnectionStrings": { "DefaultConnection": "Server=10.202.202.245;Database=test;uid=sa;pwd=password" }
可使用命令更改
dotnet ApiCenter.dll /ConnectionStrings:DefaultConnection=Server=10.15.4.155;Database=postgres;uid=root;pwd=password