參考:數據庫
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