My project contains both appsettings.json and a default appsettings.Production.json files. However an admin may edit the Production file manually on the server and it would get overwritten if I publish it again.
Can I somehow specify only this file to not be overwritten if such file already exists?
Note that this question which uses CopyToPublishDirectory="PreserveNewest" does not work because apparently it doesn't work for Web Deploy (IIS Publish) and I want it to not overwrite even if the file in the project is newer (i.e. the admin edits it before we modify it in the code).
You can exclude specific files or folders when you build a web package, by creating a custom
.wpp.targetsfile in the same folder as your web application project file.Create a custom project file named [project name].wpp.targets in the same folder as your project file.
In the .wpp.targets file, add an ItemGroup element.
In the ItemGroup element, add ExcludeFromPackageFolders and ExcludeFromPackageFiles items to exclude specific files and folders as required.
The following is the basic structure of this
.wpp.targetsfile:Then you need to add the
.wpp.targetsfile to the web application project and use this file to exclude appsettings.json and appsettings.Production.json from the web package when building the project.For more details, please refer to this document: Excluding Files and Folders from Deployment