Is there a way to exclude appsettings.json from being deployed by Azure IIS Web App Deploy task?

104 Views Asked by At

I have an API that gets deployed to a selection of locations using Azure Release Pipelines.

Some of these are azure environments (live, preprod, test, etc.) that get deployed via pipelines, and the AppSetting configuration we alter on the App Service itself via the Azure portal depending on the environment.

The others are on premises releases for our clients who self host our software. These are also deployed via release pipelines using the IIS Web App Deploy task, and are hosted on their server using IIS.

All works fine, after the first deployment we can hop on those servers and alter the appsettings.json file to contain the correct info for that environment and it works well.

The issue is when we deploy subsequent releases via the pipelines. Ideally we'd have a hands free release at a single button press, but due to the pipeline always uploading a copy of appsettings.json from the source branch and replacing the configured one on the servers, we have to log on to each and every server and make a copy of appsettings.json before the release, and then replace it after the release.

Is there a way that I can configure the IIS Web App Deploy task to exclude or skip the deployment of the appsettings.json file only? I'm fine with setting up the file after the first run or if we add new content to it, but I'd like every other release to happen without having to copy/paste the file each time.

2

There are 2 best solutions below

3
Kevin Lu-MSFT On BEST ANSWER

Is there a way that I can configure the IIS Web App Deploy task to exclude or skip the deployment of the appsettings.json file only?

Yes. You can add the following argument in the IIS Web App Deploy task to skip the deployment of the appsettings.json file.

-skip:objectName=filePath,absolutePath='folderpath\\appsettings.json' 

Or

-skip:skipAction=Update,objectName=filePath,absolutePath='folderpath\\appsettings.json' 

IIS Web App task: Add the argument to Additional Arguments

enter image description here

For more detailed info, you can refer to this blog: Demystifying MSDeploy skip rules

2
Donny Kwitty On

The general approach for different settings in different environments is to have corresponding appSettings.json files for them, such as

  • appSettings.live.json
  • appSettings.proprod.json
  • appSettings.test.json

etc.

If you also want custom settings, you could have another file that you never deploy, but only edit on the server, which would override your other settings, perhaps called appSettings.Override.json -- or whatever.