Installing the Visual Studio 2015 toolkit (v140) on a Microsoft hosted Azure Devops Build Pipeline Agent - azure-devops

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.
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:
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'
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:
##[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".
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!

Installing the Visual Studio 2015 toolkit (v140) on a Microsoft hosted Azure Devops Build Pipeline Agent
In generally you can't. If something requires admin access and you're using the hosted agent, you can't do that thing. I have test this command line in my local, I need to run the powershell with Administrator, otherwise, I will get a confirmation prompt.
Besides, MS replied:
VS has grown to a point, where installing multiple versions on the
same agent is not feasible any longer for us. Also, we notice problems
in side-by-side VS installations for certain project types. For these
reasons, we have decided to keep a single tool set going forward. If
you need multiple versions, then you would have to setup custom
agents. We are sorry that we cannot meet all of our customers'
requirements using a common hosted agent image.
So, to resolve this issue, we have to setup our private agent.
Hope this helps.

Related

Azure pipelines - How to manage versions of the tasks?

I would like to understand how the tasks work in Azure pipeline, and where can I find the documentation for it.
I have a self-hosted agent where I have installed Terraform, Azure CLI and Azure Powershell.
There are some tasks defined for them, I actually have difficulties to find them in a documentation,for example with terraform, I have to go to azure release and simulate an action of adding task, then convert that in yaml and there I have the task name:
steps:
- task: ms-devlabs.custom-terraform-tasks.custom-terraform-release-task.TerraformTaskV3#3
displayName: 'Terraform : azurerm'
inputs:
command: custom
customCommand: import
environmentServiceNameAzureRM: 'something'
Also, some tasks asks to install some resources in order to use them, will it affect the resources of my self-hosted agent? for example if we have to install the task before using it ,will it affect somehow the version of my self-hosted terraform?
I have azure powershell installed in the self-hosted agent with an old version, but there is a task that in the version parameter has the latest version, but when executing the task it uses my old version.
How versions for tasks work? Can I use the latest version or az cli without installing it in the self-hosted agent but only with the tasks for the deployments only?
- task: AzurePowerShell#5
displayName: 'DevCode'
inputs:
#azureSubscription: 'something'
azureSubscription: 'something'
ScriptPath: 'something'
azurePowerShellVersion: LatestVersion
The same for az cli.
For the commonly used pipeline tasks published by Microsoft (such as Azure CLI task and Azure PowerShell task), you can find the related documents here.
All these tasks are open-source on the GitHub repository "microsoft/azure-pipelines-tasks".
For the Terraform task, you can find it on Marketplace here and this GitHub repository.
Normally, the tasks would not change the tools have installed on your self-hosted agent machine, also not automatically install the required tools. They just call the required tools have installed on the agent machine.
For example, when you run the Azure CLI task on your self-hosted agent, if you have installed the Azure CLI tool on the agent machine, the task will call the tool to run the specified scripts. If the Azure CLI tool has not installed on the machine, normally the task will go to failure since it cannot find the required Azure CLI tool on the machine.
You do not need to manage the versions of the tasks, you just use the tasks in your pipelines and select the available released versions of the tasks (latest versions are recommended). If a new version of a task is released, you can go to edit your pipelines to use the new version.

VSBuild task not able to find vsVersion ='14.0'

In one of my pipeline, I am trying to build a solution which is created using VS2015. I am using a on-prem agent.
I am using VSBuild task as shown below
- task: VSBuild#1
inputs:
solution: '**\*.sln'
vsVersion: '14.0'
configuration: 'release'
clean: true
When I run this pipeline, in the logs I can see this warning
##[warning]Visual Studio version '14.0' not found. Falling back to version '16.0'.
Do I have to install something more in the agent? Agent capability is showing me multiple MSBuild versions
Visual Studio version 14.0 referes to Visual Stuido 2015 which is not installed on you agents based on this screenshot. So if you want to use this, you need install if on your agent.

NuGet 6 not available on Azure Pipeline

I try to update my pipeline from NET 5 to NET 6. It immediately bombed out at nuget restore saying that the used version does not support NET 6. When going to advanced settings for the NuGet tool installer therer is an i icon showing all available versions (links to https://dist.nuget.org/tools.json). That link shows 6.0.0-preview.3. If I set this and run the pipeline I get an error that latest version is 5.11.
I did add a task BEFORE to install net SDK 6 which succeeds (Successfully installed .NET Core sdk version 6.0.100-preview.3.21202.5.
Creating global tool path and pre-pending to PATH.)
So why can't it find the nuget 6 ?
Azure DevOps Pipeline's NuGetCommand task is a wrapper of nuget.exe. However, I don't recommend using nuget.exe restore to restore your projects. I bet you don't use it locally, so why not use the same tools on CI as you use for local builds.
If you build with dotnet build, then I suggest you use dotnet restore. If you build with msbuild, then I suggest you restore with msbuild -t:restore. Therefore, your pipeline should use the DotnetCoreCLI task, or MSBuild pipeline task.
Try updating the vm image defined in the yml file.
I was getting error with windows latest but allowed for nuget restore and project/solution builds.
pool:
vmImage: 'windows-2022'
This seems to be an expected behavior.
Following line filters out releases with "EarlyAccessPreview" tag.
let releasedVersions: INuGetVersionInfo[] = nugetVersions.filter(x => x.stage.toString() !== NuGetReleaseStage[NuGetReleaseStage.EarlyAccessPreview]);
Not sure if there is any possible side effect when letting user to install preview release of nuget.exe. So the task decides to download the stable released version.
For a workaround:
You could use the powershell to download the Nuget 6.0.0- preview3.
steps:
- task: PowerShell#2
inputs:
targetType: 'inline'
script: |
# Source file location
$source = 'https://dist.nuget.org/win-x86-commandline/v6.0.0-preview3/nuget.exe'
# Destination to save the file
$destination = '$(Agent.TempDirectory)\nuget.exe'
#Download the file
Invoke-WebRequest -Uri $source -OutFile $destination
For more info, you could refer to this ticket: NuGetToolInstallerV1 cannot download preview releases

Error when I run the Visual studio run task in CI

I have a .net application and I am getting below error while running Visual studio task in CI pipeline.
##[error]No agent found in pool TEST APP which satisfies the following demand: visualstudio. All demands: msbuild, visualstudio, Agent.Version -gtVersion 2.115.0
Please let me know how to resolve this.
Your pool does not contain build agents with Visual Studio. You can check your polls and agents on the administration page: Agent pools.
You have to install and register a build agent on a server or virtual machine with visual studio.
Additionally, if your project on Azure DevOps Services, you can use MS Hosted build agents. Update your yaml to:
pool:
vmImage: windows-latest
or if you use classic build, update here:

How to automate Visual Studio Code extensions packaging in Azure DevOps?

I have successfully setup Azure DevOps to automatically build my Visual Studio Code extension from a git repo, but I cannot find a way to generate the .vsix file. That is, I can create it locally, but I want to generate it for every build automatically, so I can download it once the build has finished.
Thanks!
I use this extension to generate Visual Studio extension's VSIX:
https://marketplace.visualstudio.com/items?itemName=ms-devlabs.vsts-developer-tools-build-tasks&targetId=18354d24-b805-4494-a4b9-c57440acfeea
This extension is free, and it's from Microsoft DevLabs.
It is also open source at this GitHub repo: https://github.com/Microsoft/vsts-extension-build-release-tasks
NOTE: According to my own experience using this extension, it is not compatible with some releases of Visual Studio before Visual Studio 2015 Update 1. It is compatible with Visual Studio 2015 Update 1/Update 2/Update 3, and Visual Studio 2017 release 15.3.0 or later.
In the end, I have found my own answer, by installing vsce, and calling it for packaging the .vsix
- task: Npm#1
displayName: 'Install vsce'
inputs:
command: custom
verbose: false
customCommand: 'install -g vsce'
- script: 'vsce package'
displayName: 'Package .vsix'