在實際的開發項目或産品過程中,我們會有開發環境、測試環境、生産環境;.net6也是支援多環境調試和釋出的,下面分享.net6中多環境調試的方法
1.按照上圖建立了一個開發環境的配置檔案,一個生産環境的配置檔案
公共的配置參數可以加在appsettings.json裡面,不同環境的配置參數就加在對應的配置檔案裡面
2.在launchSettings.json裡面的profiles下面,可以添加多個環境,如dev、prod、test、IIS Express等
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:33256",
"sslPort": 0
}
},
"profiles": {
"dev": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "",
"applicationUrl": "http://localhost:5149",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"prod": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "",
"applicationUrl": "http://localhost:5151",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Production"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
3.在啟動調試時,可以選擇不同的環境來調試代碼
4.測試效果