4

There is a bug in the Microsoft (R) Test Execution Command Line Tool Version 17.4.0 and we like to use 17.3.1.

We are doing dotnet test in our Azure Pipeline:

- task: UseDotNet@2
  displayName: 'Use .NET 6'
  inputs:
    packageType: 'sdk'
    version: '6.0.x'

# build tasks etc.

- task: DotNetCoreCLI@2
  displayName: Run Unit Tests
  inputs:
    command: 'test'
    projects: '$(testProjects)'
    # ... more config

But for some reason, this gives us sometimes 17.4.0 and sometimes 17.3.1 - even with the same code (rebuild of the same commit). This is probably because our build agents are shared with other teams.

Is there a way to force the version 17.3.1 of Test Execution Command Line Tool?

Background info

For the issue, see microsoft/vstest - issue #4140 - 17.4.0 Breaks pipeline code coverage

Julian
  • 33,915
  • 22
  • 119
  • 174

2 Answers2

1

For the issue about pipeline code coverage, the cause of the issue is that there are known issues with .Net7 and Test Tool version 17.4.0. For more detailed info, you can refer to this Github ticket: dotnet test does not forward MSBuild properties to msbuild in .NET 7 RC1

Is there a way to force the version 17.3.1 of Test Execution Command Line Tool?

Yes. You can force the version 17.3.1 via adding the dotnet test argument: -p:VSTestConsolePath=localpath.

Here is an example:

- task: DotNetCoreCLI@2
  displayName: Test
  inputs:
    command: test
    projects: '**/The.Tests.csproj'
    arguments: '-p:VSTestConsolePath="C:\Users\VssAdministrator\.nuget\packages\microsoft.testplatform.portable\17.3.1\tools\netcoreapp2.1\vstest.console.dll"  /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura  /p:CoverletOutput=./coverage.cobertura.xml"'

Note: you need to install the package:Microsoft.TestPlatform.Portable:17.3.1 before running the dotnet test.

On the other hand, confirmed by the Test Platform team that this issue related to Test Tool 17.4.0 will be resolved in December timeframe

Julian
  • 33,915
  • 22
  • 119
  • 174
Kevin Lu-MSFT
  • 20,786
  • 3
  • 19
  • 28
1

For vstest version 17.5.0 subdirectory of exe is netcoreapp3.1, also, be sure to add Visual Studio Test Platform Installer task before the test one. Example:

- task: VisualStudioTestPlatformInstaller@1
  inputs:
    packageFeedSelector: 'nugetOrg'
    versionSelector: 'specificVersion'
    testPlatformVersion: '17.5.0'

- task: DotNetCoreCLI@2
  inputs:
    command: 'test'
    projects: '**/*Test.csproj'
    arguments: '-p:VSTestConsolePath="C:\Users\VssAdministrator\.nuget\packages\microsoft.testplatform.portable\17.5.0\tools\netcoreapp3.1\vstest.console.dll" /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura  /p:CoverletOutput=./coverage.cobertura.xml"'
Julian
  • 33,915
  • 22
  • 119
  • 174
Vanderlei Morais
  • 556
  • 6
  • 11
  • Thanks, please note this is Windows only "##[error]This task is supported only on Windows agents and cannot be used on other platforms." – Julian Apr 25 '23 at 20:13