How to preserve user-uploaded files on WebDeploy in Azure - azure-web-app-service

In the Azure release definition I publish the build artifact to the UAT WebApp using Azure web deploy. However this deletes any previously user-uploaded files (e.g. images).
How can I release to UAT and preserve the user uploaded files?
Do I somehow need to perform the equivalent of extracting the .zip file over the existing files rather than replacing the entire website directory with the contents of the .zip?

You can add the following MSBuild property to your build
/p:SkipExtraFilesOnServer=true
OR add the MSDeploy provider flag:
-enableRule:DoNotDelete
https://dotnetcatch.com/2016/02/01/webdeploymsdeploy-quick-tip-keep-existing-files-during-deployment/

Did you try to use the -skip:Directory option to excluse the directory where the images are uploaded ? See: https://technet.microsoft.com/en-us/library/dd569089(WS.10).aspx

Related

How can I exclude a file on Azure Devops in the Deployment?

I apologize for my english, im using a translator.
I need make a deployment on Azure Devops using Continous Deployment but i need exclude a file from the repository (i cant change the repository) then create a deployment in IIS.
I have a WebService file in the repository but i cant ignore or delete it from git. I need to use Azure Devops to ignore it then make a continuous deployment.
Another approch is also to use .artifactsignore. By including this file you can describe which files you want to ignore before building the artifacts package. The tricky part here is correct placing of the file.
Where you save the .artifactignore file depends which path you have specified for the publish pipeline artifact task in your pipeline definition.
Here is good example which helped me to use it:
https://www.jfe.cloud/control-pipeline-artifacts-with-artifactignore-file/
You can use the task Delete Files, as covered below:
# Delete files
# Delete folders, or files matching a pattern
- task: DeleteFiles#1
inputs:
#SourceFolder: # Optional
#Contents: 'myFileShare'
#RemoveSourceFolder: # Optional
The input source folder can be folder $(rootFolder) or $(Build.ArtifactStagingDirectory).
I've had a similar problem and solved it this way. Especially .git or .vsfolder.

Azure DevOps - Clean up old releases on on-premise server?

I have a pipeline that deploys code to an IIS folder on an on-premise server. I'm trying to figure out how to best delete old release folders. I'm not seeing anything obvious within DevOps.
Is there a native way of doing this? Or should I roll my own PowerShell script to delete old releases?
Is there a native way of doing this?
Yes, of course there is.
Open your deploy task, go Advanced Deployment Options and then enable the option Remove Additional Files at Destination
Noted: This "delete" operation I mentioned is not mean that clear all the files in local IIS folder. It just delete the files at the destination where there's no corresponding file in the package which is being deployed.
In one word, for some files which same with previous, it will be override as the latest files. And, for any left over files from a previous deployment that are no longer required, they will be deleted.
If you do not trust this option and want to clear the previous files completely, you can also add the Powershell task before IIS manage task and run delete script.
Here is the sample script to delete local files:
Remove-Item -Path "D:\Websites2\*"
You can replace "D:\Websites2\*" as your local website file path.

Kudu Zip Deploy copies files that have not changed

The current setup is that we're using gulp to build our VS solution using MSBuild and an Azure DevOps release pipeline to deploy our build artifacts via the Kudu Zip Deploy API (via PowerShell) to our Azure App Service.
Kudu appears to copy files that are unchanged, which appears to be causing unnecessary slowness on the target server because it causes the server to restart. Here's one example:
The contents of this file have not changed (as well as other binary files), but what probably has changed is the timestamp due to the way we're generating / regenerating some of these artifact files.
I have tried to see if Kudu can be configured to ignore timestamps, but there doesn't seem to be an option for it, and it might also not be a good solution. According to the Kudu zip deploy docs:
Efficient file copy: Files will only be copied if their timestamps don't match what is already deployed. Generating a zip using a build process that caches outputs can result in faster deployments.
Other ideas include it being a misconfiguration in the solution / file settings, or an issue with the way we're building via gulp. Any ideas on how I can prevent these unchanged files from being copied?

Publish Zip Package from VSTS to Octopus Deploy

I'm trying to deploy an artifact from VSTS to an Azure App Service, using Deploy an Azure Web App step template in Octopus Deploy. The VSTS zip package will have a structure like the following:
\Content\C_C\a\1\s\Api{ProjectName\obj\Release\Package\PackageTmp
When I publish the zip file using MsDeploy.exe. It automatically only copy the folders & files inside the PackageTmp folder into the wwwroot folder. However, when I use the Octopus deploy, It copies all of the folder from Content\. Is there any way to make the Octopus deploy work like using MsDeploy.exe? I'd like to use the zip as is, so adding a Copy Files step or changing the PackageLocation in the VSTS build is not really an option.
Any help/suggestion is really appreciated.
Thank you.
To achieve the layout of the files as you describe, you will have to modify your build step. In the MSBuild arguments section on the build step, ensure you have the following parameters defined:
/p:WebPublishMethod=FileSystem /p:PackageLocation="$(build.artifactstagingdirectory)\\"
These two parameters will create the package in the directory specified by the PackageLocation parameter, and it should be in the format you expect.
In the step where you push the package to Octopus specify this directory as the Package Source.
There isn’t such setting to do it.
You can publish the web app with File System mode , then package the files through Package Application task.

Azure deploy missing XML doc files from deployment target

I have a solution. 2 projects within the solution produce XML documentation, that I need to copy to the bin folder web root when I deploy to azure.
Locally, I notice that when I build my solution, those 2 XML files get copied with the DLL into my web/bin folder. When I run my un-modified deploy.cmd file locally, I also notice that kudosync picks those up and hapilly puts them into my artifacts/wwwroot/bin folder.
But - when I deploy to azure by pushing to github, the local deployment temp folder on azure doesn't contain the XML files, and thus they don't get picked up. I added some post-build "DIR" commands to the deploy.cmd file to see what is going on, and the XML files just aren't there in the %DEPLOYMENT_TEMP%\bin\ folder.
Anyone know what's going on here?
Aha - it's because when you build from MSBUILD, it doesn't generate the XML docs for the related projects. I was getting them locally because I'd at some point built from VS, which generated them.

Resources