如何使用发布配置文件针对不同的环境

How to use publish profile to target different environment

我想使用所有这 3 个不同的预定义环境变量(开发、暂存和生产)发布我的应用程序,但我不知道如何在创建发布配置文件时针对不同的环境。

由于 .NET Core 不支持 web.config 的多版本,我无法在配置文件中使用 environmentVariable 标签来自动发布。

我也试过 launchSettings.json,在 VS 中一切似乎都很好,我可以在本地 运行 不同的环境。我也只想自动化我的发布过程,所以当我使用不同的发布配置文件然后针对不同的环境时。

dotnet publish 命令使用发布配置文件,它只打包应用程序+依赖项并使它们准备好部署:

dotnet publish compiles the application, reads through its dependencies specified in the project.json file and publishes the resulting set of files to a directory.

您通过使用 ASPNETCORE_ENVIRONMENT 环境变量在您进行部署的目标平台上指定环境。