2
votes

I am using a DotNetCoreCLI task to build a project. But I would like to build it with MSBuild 16.0 what seems to be not possible so far. Here are the facts (snippet from Azure Pipelines Yaml):

pool:
  vmImage: 'windows-2019'
steps:
- task: DotNetCoreCLI@2
  displayName: 'dotnet build'
  inputs:
    projects: '$(BuildProjectFilter)'
    arguments: '--configuration $(BuildConfiguration) -:Platform=$(BuildPlatform) -p:VisualStudioVersion=16.0 -p:tv=16.0'

No matter what I try the dotnet build command always uses ToolsVersion 15.0:

==============================================================================
Task         : .NET Core
Description  : Build, test, package, or publish a dotnet application, or run a custom dotnet command
Version      : 2.156.1
Author       : Microsoft Corporation
Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/build/dotnet-core-cli
==============================================================================
[command]C:\windows\system32\chcp.com 65001
Active code page: 65001
[command]"C:\Program Files\dotnet\dotnet.exe" build d:\a\1\s\src\xxx.csproj --configuration release -p:Platform=x64 -p:VisualStudioVersion=16.0 -p:tv=16.0
Microsoft (R) Build Engine version 15.9.20+g88f5fadfbe for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

If I only supply the -tv:16.0 switch MSBuild complains:

MSBUILD : error MSB1040: ToolsVersion is not valid. The tools version "16.0" is unrecognized. Available tools versions are "15.0".

If I supply -p:VisualStudioVersion=16.0 -p:tv=16.0 in combination the Error is recognized later by Fody telling me

 Fody is only supported on MSBuild 16 and above. Current version: 15.

Of course, downgrading Fody might be a solution. But I would prefer to use MSBuild 16 as it should be available in this vm image. Is there a way to achieve that?

1
You can try with the latest SDK version(2.2.401) to build your repos. And also, if the error still occur after this try, you'd better share more error log about only using -tv:16.0 but failed with MSB1040 error code. As normal, before this line, there will has some key info about the error caused reason. Do you mind share it in the question?Merlin Liang - MSFT

1 Answers

4
votes

I think you'd better specified the higher version of .NET core SDk 2.2.401 in your task.

If I use SDK 2.2.101 to build project, I will receive the same error message with you:

enter image description here

To explain this, you can see the below content which mentioned in the doc:

enter image description here

If the .Net Core SDK version you used is lower than 2.2.401, since these lower version SDK could not be compatible with VS2019. At this time, even you specified VS 2019, it will still use the build engine which belong to VS2017. That's why in your first error log, the build engine this pipeline used is 15.9.20+g88f5fadfbe

Microsoft (R) Build Engine version 15.9.20+g88f5fadfbe for .NET Core

As test, after I build project with the .Net Core SDK which version is 2.2.401, as the below pic you see:

enter image description here

The MSbuild version it took is 16. So, it satisfied the definition of the underlying fody file:

enter image description here

This is part of the underlying fody file. You can see, it is defined as only your MSbuild version is 16, or it will throw the error message like you received.

So, to solve your issue, I recommend you try with specifying the .Net Core SDK as 2.2.401 or above version in the task.