'How do I update my Azure DevOps on-premise Pipeline tasks to include MSBuild v17 and Visual Studio 2022?

How do I update my on-premise, Azure Devops Pipeline tasks to include the new MSBuild v17 and Visual Studio 2022 build tasks?

I found the updated MSBuild task here:
https://github.com/microsoft/azure-pipelines-tasks/tree/master/Tasks/MSBuildV1

I found the old MSBuild v16 task installed here:
C:\Program Files\Azure DevOps Server 2020\Tools\Deploy\TfsServicingFiles\Tasks\Individual\MSBuildV1\

What is the proper method to update this?



Solution 1:[1]

Until we can update our DevOps version itself, we installed Build Tools 2022 and set the msbuild path (instead of the version) in the build task settings:

MSBuild Location

Solution 2:[2]

Extension

I've published a pre-built extension that packages a copy of the current task versions from Azure DevOps (service).

This will allow you to install the tasks risk-free alongside Microsoft's older versions.

Do it yourself

You have 2 options.

  1. Download the tasks from an existing Azure DevOps organization (cloud version). Then use tfx or PowerShell to upload the upgraded tasks to your Azure DevOps server.
  2. Build the tasks from source and publish them to your Azure DevOps server.

I've outlined the process in a blog post:

https://jessehouwing.net/adding-visual-studio-2022-to-azure-devops-server-2020/

The script below is the safest, as it used the exact versions that were pushed to Azure DevOps service.

$tasksToDownload = @("VSBuild", "VsTest", "VsTestPlatformToolInstaller", 
                  "MSBuild", "DotNetCoreInstaller", "DotNetCoreCLI")

$org = "<<insert source org>>"
$pat = "<<insert PAT | Agent Pool (Manage)>>"
$projectCollectionUri = "https://yourtfs/yourcollection"

$url = "https://dev.azure.com/$org"
$header = @{authorization = "Basic $([Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes(".:$pat")))"}

$tasks = Invoke-RestMethod -Uri "$url/_apis/distributedtask/tasks" -Method Get -ContentType "application/json" -Headers $header | ConvertFrom-Json -AsHashtable

foreach ($taskName in $tasksToDownload)
{
    $taskMetadatas = $tasks.value | ?{ $_.name -ieq $taskName }
    foreach ($taskMetadata in $taskMetadatas)
    {
        $taskid = $taskMetadata.id
        $taskversion = "$($taskMetadata.version.major).$($taskMetadata.version.minor).$($taskMetadata.version.patch)"
        $taskZip = "$taskName.$taskid.$taskversion.zip"
        Invoke-WebRequest -Uri "$url/_apis/distributedtask/tasks/$taskid/$taskversion" -OutFile $taskZip -Headers $header

        & tfx build tasks upload --task-zip-path "$taskZip" --service-url $projectCollectionUri
    }
}

Required agent version

You will need to install the most recent agent from the azure-pipelines-agent repository for it to auto-detect Visual Studio 2022, or alternatively add the capabilities to the agent manually.

You may need to force Azure DevOps Server to not downgrade back to its preferred agent version. You can do so by setting the following environment variable at the system level on your server before launching the agent:

 AZP_AGENT_DOWNGRADE_DISABLED=true 

These tricks will work for most tasks in the azure-pipelines-tasks repository, as long as it doesn't depend on a UI extension or service connection type that isn't available in your version of Azure DevOps Server.

Solution 3:[3]

make sure your path is correct in the MSBuild.exe task. This will work 100%.

Path to MSBuilde => C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\MSBuild.exe

Platform => $(BuildPlatform)

Configuration => $(BuildConfiguration)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ian Horwill
Solution 2
Solution 3