Exclude/Skip files in VSTS Build and release
Asked Answered
R

4

9

We are in process of creating architecture for VSTS CI/CD to deploy our web app to our Azure App Services. We want to exclude the web.config while deploying it to the Azure server as we are directly modifying the web.config on the different environment. CI Tasks looks like this: CI Taks

CD Task: Deploy Azure App Service I am aware of other ways of updating the web.config https://learn.microsoft.com/en-us/vsts/build-release/tasks/transforms-variable-substitution, but in our case we want to skip the web.config file. I couldn’t find the option to skip file in during release in VSTS as mentioned in this thread How do I exclude the .cs files within an artifact from a vs-team-services CI build? Is there a way to exclude certain files while building and deploying the release?

Redmon answered 25/10, 2017 at 15:20 Comment(2)
Is your build process generating a webdeploy package?Yalonda
Hey Daniel. Answer is 'Yes'Redmon
R
19

Added -skip:objectName=filePath,absolutePath=web\.config in additional arguments. This skips updating the web.config file during deployment. Azure App Service Deployment

Redmon answered 26/10, 2017 at 18:8 Comment(1)
This answer does the job! In case someone wants to skip an entire folder: instead of objectName=filePath, use objectName=dirPath. This article explains some other options too.Lanky
P
10

You can exclude the web.config before publishing artifacts in your build definition: copy the web packages files to a directory (such as $(build.binariesdirectory)), then copy the files exclude web.config to another folder (such as $(Build.ArtifactStagingDirectory)/package), and zip the files under $(Build.ArtifactStagingDirectory)/package. And finally publish the zip file as build artifacts.

Details changes in the build definition as below:

  1. Change the MSbuild arguments as /p:OutDir="$(build.binariesdirectory)\\" in Visual Studio Build task.

    enter image description here

  2. Add a Copy Files task after Visual Studio Build task. Settings for this task as below:

    enter image description here

  3. Add Archive Files task after Copy Files task. And settings as below:

    enter image description here

  4. Change the Publish Artifacts task as below:

    enter image description here

Now the build artifacts are exclude web.config file.

Polymerization answered 26/10, 2017 at 7:0 Comment(2)
thanks Marina for providing steps by step solution. This definitely looks like a solution to the problem. One other resolution that i got from 'Azure App Service Deployment ' team also worked. I am putting the resolution below.Redmon
Yes, the solution you provided is more easier and efficient. You can mark you own answer, and it will benefit others who have similar question.Polymerization
N
2

Additional arguments

-skip:objectName=filePath,absolutePath=\\Configuration\\AppSettings\\Base.config

enter image description here

Nyeman answered 24/4, 2019 at 4:34 Comment(2)
properly edit your answer like give some details, put image in answer otherwise you get downvoted.Pantaloons
How can I exclude multiple files using -skip:objectName=filePath,absolutePath=filepathRobison
E
1

you can add

-skip:objectName=filePath,absolutePath='.*\PackageTmp\Web.config$'

in Additional Arguments in "Deploy IIS WebSite/App" deployment VSTS task, this will not deploy your root web.config file.

Effortful answered 23/10, 2019 at 14:37 Comment(1)
check your .config absolute Path? for .Net core the path is different. for example if your application built in .net core use -skip:objectName=filePath,absolutePath='.*\\nlog.config$' -skip:objectName=filePath,absolutePath='.*\\appsettings.json$'Effortful

© 2022 - 2024 — McMap. All rights reserved.