azure-pipelines-tasks: MSBuild task does not recognize VS2019

At first glance, this issue seems to be partly in:

  1. Select-MSBuildPath (located in Tasks\Common\MSBuildHelpers\PathFunctions.ps1), which has a hardcoded list of versions that goes up to 15.0
$versions = '15.0', '14.0', '12.0', '4.0' | Where-Object { $_ -ne $PreferredVersion }
  1. Get-MSBuildPath which only does the vswhere.exe query when $version is 15.0 (also in Tasks\Common\MSBuildHelpers\PathFunctions.ps1)
        if (($Version -eq "15.0" -or !$Version) -and # !$Version indicates "latest"
            ($visualStudio15 = Get-VisualStudio_15_0) -and
            $visualStudio15.installationPath) {

            $msbuildUtilitiesPath = [System.IO.Path]::Combine($visualStudio15.installationPath, "MSBuild\15.0\Bin\Microsoft.Build.Utilities.Core.dll")
            if (Test-Path -LiteralPath $msbuildUtilitiesPath -PathType Leaf) {
                Write-Verbose "Loading $msbuildUtilitiesPath"
                $msUtilities = [System.Reflection.Assembly]::LoadFrom($msbuildUtilitiesPath)
            }
        }

        # Fallback to searching the GAC.
        # ...
  1. Get-VisualStudio_15_0, which is fine by itself but probably needs to be refactored to handle 16.0 (similar to the change made to detect VS2019 for agent capabilities in https://github.com/Microsoft/azure-pipelines-agent/pull/2005)

Environment

  • Server - Azure Pipelines

    • If using Azure Pipelines, provide the account name, team project name, build definition name/build number:
  • Agent: Private:

    • If using private agent, provide the OS of the machine running the agent and the agent version: Agent is running Win2012R2 and the agent version is 2.144.1.

Issue Description

When using the MSBuild task on an agent which has VS2019 installed, the agent does not detect that instance of VS and will fallback to an earlier MSBuild agent.

In the log below, it fails to find the instance for VS 2019 (16.0), and falls back to MSBuild v4.0 as ships with .NET framework (the build then fails because of the /bl flag, which was introduced to MSBuild in 15.3).

Task logs

2018-12-18T21:52:06.0260909Z ##[section]Starting: Build (Debug) 2018-12-18T21:52:06.0449497Z ============================================================================== 2018-12-18T21:52:06.0449605Z Task : MSBuild 2018-12-18T21:52:06.0449682Z Description : Build with MSBuild 2018-12-18T21:52:06.0449739Z Version : 1.120.2 2018-12-18T21:52:06.0449790Z Author : Microsoft Corporation 2018-12-18T21:52:06.0449862Z Help : More Information 2018-12-18T21:52:06.0449913Z ============================================================================== 2018-12-18T21:52:07.5293907Z ##[command]“D:\agent_work_tasks\MSBuild_c6c4c611-aa2e-4a33-b606-5eaba2196824\1.120.2\ps_modules\MSBuildHelpers\vswhere.exe” -version [15.0,16.0) -latest -format json 2018-12-18T21:52:07.5983764Z ##[command]“D:\agent_work_tasks\MSBuild_c6c4c611-aa2e-4a33-b606-5eaba2196824\1.120.2\ps_modules\MSBuildHelpers\vswhere.exe” -version [15.0,16.0) -products Microsoft.VisualStudio.Product.BuildTools -latest -format json 2018-12-18T21:52:07.8418751Z ##[command]“C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe” “d:\agent_work\2\s\Extensions.msbuild” /nologo /nr:false /dl:CentralLogger,“D:\agent_work_tasks\MSBuild_c6c4c611-aa2e-4a33-b606-5eaba2196824\1.120.2\ps_modules\MSBuildHelpers\Microsoft.TeamFoundation.DistributedTask.MSBuild.Logger.dll”;“RootDetailId=|SolutionDir=d:\agent_work\2\s”*ForwardingLogger,“D:\agent_work_tasks\MSBuild_c6c4c611-aa2e-4a33-b606-5eaba2196824\1.120.2\ps_modules\MSBuildHelpers\Microsoft.TeamFoundation.DistributedTask.MSBuild.Logger.dll” /t:SetupAll /bl:LogFile=d:\agent_work\2\a\Logs\DebugBuild.binlog /p:_MSDeployUserAgent=“VSTS_5dff9b53-b23e-4d16-b57b-fda3d1a4eac2_build_7_0” 2018-12-18T21:52:07.9224611Z MSBUILD : error MSB1001: Unknown switch. 2018-12-18T21:52:07.9225212Z Switch: /bl:LogFile=d:\agent_work\2\a\Logs\DebugBuild.binlog 2018-12-18T21:52:07.9225381Z 2018-12-18T21:52:07.9225474Z For switch syntax, type “MSBuild /help” 2018-12-18T21:52:08.1255312Z ##[error]Process ‘msbuild.exe’ exited with code ‘1’. 2018-12-18T21:52:08.1765835Z ##[section]Finishing: Build (Debug)

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 26 (11 by maintainers)

Most upvoted comments

@mika76 Thanks! Let me close this one since this resolved - please feel free to ask any further questions