2
votes

Web api is deployed in an on-premise web server. I have setup the release pipeline through azure devops. Now looking for a way to remove appsettings.env.json after deployment is complete

such that:

appsettings.Development.json and appsettings.Staging.json are removed from the target directory of the production environment after the app is deployed.

2

2 Answers

1
votes

You can try Delete Files task.

The UI interface operation is as follows, add a Delete files from task to the Deployment group job. enter image description here

And then add the files you want to delete, that is, the paths specified by appsettings.Development.json and appsettings.Staging.json.

enter image description here

Save and run when you are done.

0
votes

As long as you have specified the Environment key in the web.config file, other files will not be included. `

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();
}
...`

So it would be fine even if you will not delete the other files.