Skip to content

Instantly share code, notes, and snippets.

@umair-me
Last active May 22, 2025 12:50
Show Gist options
  • Save umair-me/fcd112bba9a8c5d3a3a3fb1d1422e5f7 to your computer and use it in GitHub Desktop.
Save umair-me/fcd112bba9a8c5d3a3a3fb1d1422e5f7 to your computer and use it in GitHub Desktop.
Azure DevOps YAML WebDeploy .net

Custom variables defined in the yaml file:

  • ProdDeploySiteWeb - website name on IIS
  • ProdDeploySiteUrl - IP address or url of the server, usually in the below format:
  • ProdDeploySiteUsername - username for web deploy
  • ProdDeploySitePassword - password for web deploy
trigger:
- main
variables:
  solution: '**/*.sln'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Release'
stages:
- stage: Build
  displayName: "Build"
  jobs:
  - job: Build
    displayName: "Build"
    pool:
      vmImage: 'windows-latest'
    steps:
    - task: DotNetCoreCLI@2
      displayName: Restore
      inputs:
        command: 'restore'
        projects: '**/*.csproj'
        feedsToUse: 'select'
    - task: DotNetCoreCLI@2
      displayName: Build
      inputs:
        command: 'build'
        projects: '**/*.csproj'
    - task: DotNetCoreCLI@2
      displayName: Publish Web
      inputs:
        command: 'publish'
        publishWebProjects: false
        projects: '**/MyProject.Web.csproj'
        arguments: '--configuration $(BuildConfiguration) --output $(Build.ArtifactStagingDirectory)'
    - task: PublishBuildArtifacts@1
      displayName: Publish Artifacts
      inputs:
        PathtoPublish: '$(Build.ArtifactStagingDirectory)'
        ArtifactName: 'drop'
        publishLocation: 'Container'
- stage: DeployProd
  displayName: "Deploy to Production"
  trigger: manual
  jobs:
    - job: Deploy
      displayName: "Deploy"
      pool:
        vmImage: 'windows-latest'
      steps:
        - checkout: none
        - task: DownloadBuildArtifacts@1
          displayName: "Download Artifacts"
          inputs:
            buildType: 'current'
            downloadType: 'specific'
            itemPattern: 'drop\**'
            downloadPath: '$(System.ArtifactsDirectory)'
        - task: ExtractFiles@1
          displayName: "Extract Web"
          inputs:
            archiveFilePatterns: '$(System.ArtifactsDirectory)\drop\MyProject.Web.zip'
            destinationFolder: '$(System.ArtifactsDirectory)\MyProject.Web'
            cleanDestinationFolder: true
            overwriteExistingFiles: true
        - task: CmdLine@2
          displayName: "Deploy Web"
          inputs:
            workingDirectory: 'C:\Program Files (x86)\IIS\Microsoft Web Deploy V3\'
            script: msdeploy.exe -verb:sync -source:contentPath="$(System.ArtifactsDirectory)/MyProject.Web" -dest:contentPath="$(ProdDeploySiteWeb)",ComputerName="$(ProdDeploySiteUrl)$(ProdDeploySiteWeb)",UserName="$(ProdDeploySiteUsername)",Password="$(ProdDeploySitePassword)",AuthType="Basic" -enableRule:AppOffline -enableRule:DeleteFilesRule
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment