Visual Studio 2022 not listed in devops build solution pipeline task
Asked Answered
T

5

13

I have an on-prem instance of Azure DevOps 2020.1.1 in the build pipeline I have a build solution task which has visual studio version set to "latest" when building a .NET6 project this fails saying of course .NET6 isn't supported because the latest version it seems to recognize is 2019, 2022 isn't even listed in the visual studio versios drop down.

I have installed visual studio 2022 on the server and the build agents see it (they were updated to the latest agents version).

How do I get the latest visual studio version to show as 2022 in the build solution task? MS hasn't released any updates for the on-prem server for this yet that I know of, is there a way to add it or make it find it?

Tocci answered 30/11, 2021 at 18:53 Comment(1)
Had the same scenario back with the release for Visual Studio 2019. The response at the time was that I just had to wait on a patch/release to include it for the built-in task.Intensive
S
11

The trick is to use a MSBUILD task and switch from Version to Specify Location and insert the path to the msbuild.exe of VS2022 e.g. C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\MSBuild\Current\Bin\msbuild.exe.

EDIT:

Another way is to use a Command line task and call the executable directly. If you need the complete VS development environment to build your application, than specify the path of the executable in the Tool field for example as "C:\Program Files\Microsoft Visual Studio\2022\Professional\Common7\IDE\devenv.com" and specify the solution and configuration in the Arguments field for example as "MySolution.sln /build "Release|Any CPU".

Soho answered 22/12, 2021 at 10:28 Comment(2)
Thanks that worked for me too. Just in case someone needs this info: 1. Select your Pipeline, 2. Edit, 3. Agent Job 1 "+" Button (Add), then select MSBuild. 4. Specify the msbuild.exeDecathlon
Works. But the correct path is C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Current\Bin\MSBuild.exe (or similar for Community etc..)Quito
D
6

Look at the screenshot below: enter image description here

Please make sure your path is correct in the MSBuild.exe task

Dratted answered 27/3, 2022 at 3:29 Comment(0)
P
4

You can build Microsoft's task yourself and push these tasks directly into your project collection using tfx-cli. You can also create an extension containing these updates tasks and install that into your collection.

To build the tasks you can run this script in PowerShell 7:

$tasksToBuild = @("VSBuildV1", "VsTestV1", "VsTestV2", "VsTestPlatformToolInstallerV1", 
                  "MSBuildV1", "DotNetCoreInstallerV1", "DotNetCoreCLIV2")

$outputDir = md _build -force

$extensionManifest = gc "vss-extension.json" | ConvertFrom-Json
$extensionManifest.contributions = @()

& git clone https://github.com/microsoft/azure-pipelines-tasks.git --quiet
cd azure-pipelines-tasks

& git config --local pager.branch false
$branches = & git branch -r
$version = (($branches | Select-String -pattern "(?<=origin/releases/m)\d+$").Matches) | %{ [int32]$_.Value } | measure-object -maximum
$version = $version.Maximum

& git reset --hard origin/releases/m$version

npm install

Write-Host "Building tasks..."
foreach ($task in $tasksToBuild)
{
    Write-Host "Building $task..."
    & node make.js build --task $task
    Write-Host "Building $task done."
    
    $taskDir = "$outputDir/$task"
    copy "./_build/Tasks/$task" $taskDir -Recurse

    Write-Host "Updating contributions..."
    $extensionManifest.contributions += @{
        "id" = "$task"
        "type" = "ms.vss-distributed-task.task"
        "targets" = @("ms.vss-distributed-task.tasks")
        "properties" = @{
            "name" = "_build/$task"
        }
    }
}

cd ..

$extensionManifest.version = "1.$version.0"
$extensionManifest | ConvertTo-Json -depth 100 | Out-File "vss-extension.json" -Encoding utf8NoBOM

& npm install tfx-cli -g
& tfx extension create --manifests vss-extension.dev.json vss-extension.json --output tasks.vsix

From:

Make sure you have an extension manifest available in the folder when you run this script. You can look at this repo for an example:

Replace the contents of build.ps1 with the script above, update the vss-extension.*.json files with your own publisher and extensionid and it should spit out an extension for you.

That way you'll get a copy of the exact tasks Microsoft published in the latest release of Azure DevOps (cloud).

I've documented these steps along with a few more options on my blog.

Permission answered 30/11, 2021 at 19:59 Comment(0)
Q
0

Switching to the MSBuild task did not solve it for me, but what did work was changing the Pipeline Agent Specification from windows-2019 to windows-latest or windows-2022. This caused it to start using the windows-2022 VM image which apparently includes Visual Studio 2022, but windows-2019 only had VS 2019.

Note that the C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Current\Bin\MSBuild.exe path also does not work anymore, because it's using the new Rosyln C# compiler at:

C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\Roslyn\csc.exe

One other required change was to update the NuGet package restore to the latest version.

Quadrisect answered 29/8, 2022 at 15:34 Comment(0)
K
0

The problem may be the agent version you are using.

This Microsoft Github bugfix post lays it out clearly: Update PowerShellCapabilitiesProvider to work with Visual Studio 2022 #3571 This bugfix appeared in three agent releases: 2.195.0, 2.195.1 and 2.195.2. I'm not sure which agent release actually fixed the problem.

In short, build agents prior to 2.195.2 did not have the ability to natively recognize VS2022 and the new path to the updated build tools.

Kugler answered 13/9, 2023 at 1:6 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.