title: Installing the Visual Studio 2015 toolkit (v140) on a Microsoft hosted Azure Devops Build Pipeline Agent
body: <p>I have a legacy solution that we've moved into an Azure Devops git repo and I am trying to setup a build pipeline for it. The solution is a mixture of v141 (2017) and v140 (2015) projects, which on my local machine I can just build in Visual Studio 2017 as long as I've installed the v140 toolset.</p>
  
  <p>Ideally, I'd like to use a Microsoft provided agent but it seems like the vs2017-win2016 image does not include the v140 toolset by default. As this is not something we are planning to build very often, I attempted to install the v140 toolset using the 2017 installer:</p>
  
  <pre><code>pool:
      vmImage: 'vs2017-win2016'
  
  steps:
  - task: PowerShell@2
    displayName: 'Install Visual Studio v140 Toolset'
    inputs:
      targetType: 'inline'
      script: |
        Write-Output "Starting the installation process. This will take some time"
        $installProcess = Start-Process -FilePath $(Build.SourcesDirectory)/External/VisualStudioBuildTools/installer.exe -ArgumentList "--add Microsoft.VisualStudio.Component.VC.140", "--quiet", "--wait", "--norestart" -Wait -PassThru
        Write-Output "Install Completed with code $($process.ExitCode)"
  
  - task: VSBuild@1
    displayName: 'Build Debug [.sln]'
    inputs:
      solution: '$(Build.SourcesDirectory)/LegacySolution.sln'
      vsVersion: '15.0'
      configuration: 'Debug'
      platform: 'x64'
  </code></pre>
  
  <p>When I run this in Azure Devops, the install process exits with code 0 (success) after about a minute. However, when it then tries to build the solution it fails with:</p>
  
  <pre><code>##[error]C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\VC\VCTargets\Microsoft.Cpp.Platform.targets(67,5): Error MSB8020: The build tools for v140 (Platform Toolset = 'v140') cannot be found. To build using the v140 build tools, please install v140 build tools.  Alternatively, you may upgrade to the current Visual Studio tools by selecting the Project menu or right-click the solution, and then selecting "Retarget solution".
  </code></pre>
  
  <p>Has anyone tried this before with any luck? The only other thing I can think of is to try to check in a copy of the v140 toolset and play with adding it correctly to the path, but I can see this being a major pain to get right!</p>