asp.net核心在发布/部署后针对不同的环境删除appsettings.json

问题描述 投票:1回答:2

Web api部署在本地Web服务器中。我已经通过azure devops设置了发布管道。现在正在寻找一种在部署完成后删除appsettings.env.json的方法

诸如:

appsettings.Development.json和appsettings.Staging.json在部署应用程序后从生产环境的目标目录中删除。

asp.net-core azure-devops asp.net-core-2.0 azure-pipelines azure-pipelines-release-pipeline
2个回答
0
投票

您可以尝试Delete Files task

UI界面操作如下,将“从任务中删除文件”添加到“部署”组作业。enter image description here

然后添加要删除的文件,即由appsettings.Development.json和appsettings.Staging.json指定的路径。

enter image description here

完成后保存并运行。


0
投票

只要您在web.config文件中指定了环境密钥,其他文件将不包括在内。`

public Startup(IHostingEnvironment env)
{
    var builder = new ConfigurationBuilder()
        .SetBasePath(env.ContentRootPath)
        .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
        .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
        .AddEnvironmentVariables();

    this.Configuration = builder.Build();
}
...`

所以即使您不删除其他文件也可以。

© www.soinside.com 2019 - 2024. All rights reserved.