11

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?

jessehouwing
  • 106,458
  • 22
  • 256
  • 341
BlueBSH
  • 291
  • 3
  • 9
  • 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. – Matt Nov 30 '21 at 19:27

6 Answers6

9

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".

  • 1
    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.exe – Lumo Jan 21 '22 at 15:25
  • Works. But the correct path is C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Current\Bin\MSBuild.exe (or similar for Community etc..) – Cesar Mar 30 '22 at 14:00
5

Look at the screenshot below: enter image description here

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

Rohan Rao
  • 2,505
  • 3
  • 19
  • 39
qaguru
  • 81
  • 2
  • 5
2

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.

jessehouwing
  • 106,458
  • 22
  • 256
  • 341
0

I've switch to a straight out MSBUILD task instead of a solution task, solves the problem for me :)

BlueBSH
  • 291
  • 3
  • 9
  • 1
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Dec 09 '21 at 00:01
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.

Bryan Williams
  • 452
  • 1
  • 5
  • 17
-1

Edit PathFunctions.ps1 file located at ..\agent\_work\_tasks\VSBuild_71a9a2d3-a98a-4caa-96ab-affca411ecda\1.166.2\ps_modules\MSBuildHelpers\ replace $($MajorVersion+1).0) by $($MajorVersion+2).0) in lines 199 and 218.

AhmadYo
  • 334
  • 3
  • 6