title: How to auto merge all code to another branch in azure devops with TFVC?
body: <p>Our previous on-prem TFS ran XAML builds. Once a changeset had been processed the XAML ran some power shell to map both branches to temp folders, and get the code that was different between them and auto-merge from trunk to branch.</p>
  
  <p>I’m trying to use Classic Pipelines in Azure Devops Services (cloud)  to achieve the same result.
  The power shell script runs but I think it’s not authenticated, or the workspace isn’t deterministic. There’s no visible errors in the power shell output in dev.azure.com. 
  The power shell script ran tf.exe commmands.</p>
  
  <p>I thought there might be an azure devops task that could do this common operation (merge a change set). I’ve seen some solutions for git, but nothing for TFVC (Cloud based).</p>
  
  <p>Here's the powershell so you can see what we do:</p>
  
  <pre><code># Get the tfs command line tool
  $tf = get-item "C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\TF.EXE"
  $rootBranchLocation = "C:\temp\M16"
  $branchBranchLocation = "C:\temp\M16Branch"
  $rootBranch="$/MooD/M16" 
  $branchBranch="$/MooD/M16Branch" 
  
  if(!(Test-Path -Path $rootBranchLocation )){
      New-Item -Path $rootBranchLocation -ItemType Directory
  }
  if(!(Test-Path -Path $branchBranchLocation )){
  New-Item -Path $branchBranchLocation -ItemType Directory
  }
  
  # Temporarily map the two branches so we can do the merge etc. Do not need to do a get. Shouldn't be slow.
  &amp; $tf workfold /map $rootBranch $rootBranchLocation
  &amp; $tf workfold /map $branchBranch $branchBranchLocation
  
  # List the changes that haven't been merged yet
  Write-Host (&amp; $tf merge /candidate $rootBranchLocation $branchBranchLocation /recursive)
  # Try do the merge
  &amp; $tf merge $rootBranchLocation $branchBranchLocation /recursive /noprompt
  # Get the exit code for the merge
  $exitMerge=$LastExitCode
  # If the exit code was 0 then there were no conflicts (or no changes) so do a check in into the branch
  if ($exitMerge -eq 0) { 
      &amp; $tf checkin /comment:"Automerge from M16" /recursive /noprompt /notes:"Code Reviewer"="None - Automerge";   
      # Get the exit code for the checkin
      $exitCheckin=$LastExitCode
      # If you checkin with no changes the you get an errorlevel 1
      if ($exitCheckin -eq 1) { $exitCheckin=0 } 
  }
  
  # Unmap the two branches we set up 
  &amp; $tf workfold /unmap $rootBranchLocation
  &amp; $tf workfold /unmap $branchBranchLocation
  
  if ($exitMerge -ne 0) {
      Write-Error ("Merge to M16Branch did not complete. The most likely cause is conflict. Try manual merge")
      exit 1
  }
  
  exit 0
  </code></pre>
  
  <p>But it would be awesome if we didn't need the powershell script at all.</p>