ASP.NET Bundling + CI/CD - how to handle when a bundled file is deleted or renamed

New Contributor

We are using Azure DevOps to run a CI/CD pipeline to our various environments. We recently encountered an issue where one of the developers re-named a TypeScript file - perfectly reasonable thing to do - and then pushed his changes to BitBucket.


When the pipeline ran, the new output file was deployed to the target server, but because there was no cleaning process, the same file was already there with it's old name. Then subsequently when the bundle was served to the browser, it included the contents of both files and so we had instances of "Identifier 'x' has already been declared".


Just wondering if anyone has a neat way of handling this situation. Do you include a clean-up step in the pipeline?


4 Replies
Need to know couple of inputs:
- Are you using YAML way of using the CI/CD or the classic?
- whats the target of your deployment - App Service or VM?
- What task are you using to do the deployment in your pipeline? Can you describe your deployment steps in detail


Thanks for the reply. Apologies, wasn't sure what detail I needed to include.


We are using a YAML file to define the pipeline steps. It is deploying to a VM. 


Deployment steps are as follows:


- stage: Deploy
  displayName: Deploy to IIS
  dependsOn: Build
  - deployment: DeploytoIIS
    displayName: Deploy the web application to dev environment
      name: Development-env-02
      resourceType: VirtualMachine
          - task: DownloadBuildArtifacts@0
              buildType: 'current'
              downloadType: 'specific'
              downloadPath: '$(System.ArtifactsDirectory)'
          - task: IISWebAppDeploymentOnMachineGroup@0
            displayName: 'Deploy IIS Website'
              WebSiteName: '$(websiteName)'
              Package: '$(System.ArtifactsDirectory)\**\'


So maybe there is a clean step we can include?


best response confirmed by DarrenMArdex (New Contributor)
Thanks for the details.

Take a look at the task documentation here:

It has a flag called RemoveAdditionalFilesFlag. Its a boolean flag. According to the flag description from documentation - it is supposed to "Remove Additional Files at Destination". By default the value for this flag is false. So the deployment wont remove any additional files present on the server that was not present in the currently deployed deployment.

I believe this is the flag you are looking for.

Let me know If this works for you.

Hope this helps you.
That looks to be exactly what I want. Will give it a try, thanks!