azure-pipelines-tasks: [BUG]: DotNetCoreCLI@2 to run tests occasionally fails with error MSB1008: Only one project can be specified

Task name

DotNetCoreCLI

Task version

2.221.0

Environment type (Please select at least one enviroment where you face this issue)

  • Self-Hosted
  • Microsoft Hosted
  • VMSS Pool
  • Container

Azure DevOps Server type

dev.azure.com (formerly visualstudio.com)

Operation system

OS: Windows Container image: onebranch.azurecr.io/windows/ltsc2019/vse2022:latest

Task log

When works:

Starting: Run tests (windows_build_container)
==============================================================================
Task         : .NET Core
Description  : Build, test, package, or publish a dotnet application, or run a custom dotnet command
Version      : 2.221.0
Author       : Microsoft Corporation
Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/build/dotnet-core-cli
==============================================================================
C:\Windows\system32\chcp.com 65001
Active code page: 65001
Info: .NET Core SDK/runtime 2.2 and 3.0 are now End of Life(EOL) and have been removed from all hosted agents. If you're using these SDK/runtimes on hosted agents, kindly upgrade to newer versions which are not EOL, or else use UseDotNet task to install the required version.
C:\__t\dotnet\dotnet.exe test C:\__w\1\s\src\Service.Tests.Functional\Service.Tests.Functional.csproj --no-restore --no-build --configuration Release --settings C:\__w\1\s\.runsettings --filter TestCategory!=Integration --blame --collect "Code coverage" --logger trx --results-directory C:\__w\_temp\TestResults\ /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura /p:CoverletOutput=C:\__w\_temp\TestResults\

Welcome to .NET 7.0!
---------------------
SDK Version: 7.0.306

Telemetry
---------
The .NET tools collect usage data in order to help us improve your experience. It is collected by Microsoft and shared with the community. You can opt-out of telemetry by setting the DOTNET_CLI_TELEMETRY_OPTOUT environment variable to '1' or 'true' using your favorite shell.

Read more about .NET CLI Tools telemetry: https://aka.ms/dotnet-cli-telemetry

----------------
Installed an ASP.NET Core HTTPS development certificate.
To trust the certificate run 'dotnet dev-certs https --trust' (Windows and macOS only).
Learn about HTTPS: https://aka.ms/dotnet-https
----------------
Write your first app: https://aka.ms/dotnet-hello-world
Find out what's new: https://aka.ms/dotnet-whats-new
Explore documentation: https://aka.ms/dotnet-docs
Report issues and find source on GitHub: https://github.com/dotnet/core
Use 'dotnet --help' to see available commands or visit: https://aka.ms/dotnet-cli
--------------------------------------------------------------------------------------
Test run for C:\__w\1\s\src\Service.Tests.Functional\bin\Release\net7.0\Azure.Throttling.ResourceProvider.Service.Tests.Functional.dll (.NETCoreApp,Version=v7.0)
Microsoft (R) Test Execution Command Line Tool Version 17.6.3 (x64)
Copyright (c) Microsoft Corporation.  All rights reserved.

Starting test execution, please wait...
A total of 1 test files matched the specified pattern.
Results File: C:\__w\_temp\TestResults\ContainerAdministrator_6D5F55668976_2023-07-28_22_38_11.trx

Passed!  - Failed:     0, Passed:     2, Skipped:     0, Total:     2, Duration: 3 s - Azure.Throttling.ResourceProvider.Service.Tests.Functional.dll (net7.0)

Url: https://dev.azure.com/msazure/One/_build/results?buildId=77041080&view=logs&j=fa1208be-7322-5e86-1637-d1f5bee81ceb&t=6b44f5bc-7ea1-5a94-5862-d9bc9577db38&l=117

When fails:

Starting: Run tests (windows_build_container)
==============================================================================
Task         : .NET Core
Description  : Build, test, package, or publish a dotnet application, or run a custom dotnet command
Version      : 2.221.0
Author       : Microsoft Corporation
Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/build/dotnet-core-cli
==============================================================================
C:\Windows\system32\chcp.com 65001
Active code page: 65001
Info: .NET Core SDK/runtime 2.2 and 3.0 are now End of Life(EOL) and have been removed from all hosted agents. If you're using these SDK/runtimes on hosted agents, kindly upgrade to newer versions which are not EOL, or else use UseDotNet task to install the required version.
C:\__t\dotnet\dotnet.exe test C:\__w\1\s\src\Service.Tests.Functional\Service.Tests.Functional.csproj --no-restore --no-build --configuration Release --settings C:\__w\1\s\.runsettings --filter TestCategory!=Integration --blame --collect "Code coverage" --logger trx --results-directory C:\__w\_temp\TestResults\ /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura /p:CoverletOutput=C:\__w\_temp\TestResults\

Welcome to .NET 7.0!
---------------------
SDK Version: 7.0.306

Telemetry
---------
The .NET tools collect usage data in order to help us improve your experience. It is collected by Microsoft and shared with the community. You can opt-out of telemetry by setting the DOTNET_CLI_TELEMETRY_OPTOUT environment variable to '1' or 'true' using your favorite shell.

Read more about .NET CLI Tools telemetry: https://aka.ms/dotnet-cli-telemetry

----------------
Installed an ASP.NET Core HTTPS development certificate.
To trust the certificate run 'dotnet dev-certs https --trust' (Windows and macOS only).
Learn about HTTPS: https://aka.ms/dotnet-https
----------------
Write your first app: https://aka.ms/dotnet-hello-world
Find out what's new: https://aka.ms/dotnet-whats-new
Explore documentation: https://aka.ms/dotnet-docs
Report issues and find source on GitHub: https://github.com/dotnet/core
Use 'dotnet --help' to see available commands or visit: https://aka.ms/dotnet-cli
--------------------------------------------------------------------------------------
MSBUILD : error MSB1008: Only one project can be specified.
    Full command line: 'c:\__t\dotnet\sdk\7.0.306\MSBuild.dll -maxcpucount -verbosity:m -target:VSTest -nodereuse:false -nologo -property:VSTestSetting="C:\__w\1\s\.runsettings" -property:VSTestTestCaseFilter="TestCategory!=Integration" -property:VSTestLogger="trx" -property:VSTestNoBuild=true -property:VSTestResultsDirectory="C:\__w\_temp\TestResults\\" -property:VSTestCollect="Code" -property:VSTestBlame=true -property:Configuration=Release C:\__w\1\s\src\Service.Tests.Functional\Service.Tests.Functional.csproj coverage -p:UseSharedCompilation=false -p:EmitCompilerGeneratedFiles=true /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura /p:CoverletOutput=C:\__w\_temp\TestResults\ -property:VSTestArtifactsProcessingMode=collect -property:VSTestSessionCorrelationId=12004_c1861575-f585-432f-9f5a-74d822feaa59 -distributedlogger:Microsoft.DotNet.Tools.MSBuild.MSBuildLogger,c:\__t\dotnet\sdk\7.0.306\dotnet.dll*Microsoft.DotNet.Tools.MSBuild.MSBuildForwardingLogger,c:\__t\dotnet\sdk\7.0.306\dotnet.dll'
  Switches appended by response files:
Switch: coverage

For switch syntax, type "MSBuild -help"
##[error]Error: The process 'C:\__t\dotnet\dotnet.exe' failed with exit code 1
C:\__t\dotnet\dotnet.exe test C:\__w\1\s\src\Service.Tests.Integration\Service.Tests.Integration.csproj --no-restore --no-build --configuration Release --settings C:\__w\1\s\.runsettings --filter TestCategory!=Integration --blame --collect "Code coverage" --logger trx --results-directory C:\__w\_temp\TestResults\ /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura /p:CoverletOutput=C:\__w\_temp\TestResults\
MSBUILD : error MSB1008: Only one project can be specified.
    Full command line: 'c:\__t\dotnet\sdk\7.0.306\MSBuild.dll -maxcpucount -verbosity:m -target:VSTest -nodereuse:false -nologo -property:VSTestSetting="C:\__w\1\s\.runsettings" -property:VSTestTestCaseFilter="TestCategory!=Integration" -property:VSTestLogger="trx" -property:VSTestNoBuild=true -property:VSTestResultsDirectory="C:\__w\_temp\TestResults\\" -property:VSTestCollect="Code" -property:VSTestBlame=true -property:Configuration=Release C:\__w\1\s\src\Service.Tests.Integration\Service.Tests.Integration.csproj coverage -p:UseSharedCompilation=false -p:EmitCompilerGeneratedFiles=true /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura /p:CoverletOutput=C:\__w\_temp\TestResults\ -property:VSTestArtifactsProcessingMode=collect -property:VSTestSessionCorrelationId=11492_262230af-5788-4b84-920a-ae99d8544e38 -distributedlogger:Microsoft.DotNet.Tools.MSBuild.MSBuildLogger,c:\__t\dotnet\sdk\7.0.306\dotnet.dll*Microsoft.DotNet.Tools.MSBuild.MSBuildForwardingLogger,c:\__t\dotnet\sdk\7.0.306\dotnet.dll'

Url: https://dev.azure.com/msazure/One/_build/results?buildId=77263266&view=logs&j=15dfcb1a-0989-5cf6-3160-3e181e44de87&t=d80a394b-d4ad-5cf4-e035-192d3dcb341d&l=41

Relevant log output

Dotnet command failed with non-zero exit code on the following projects : [ 'C:\\__w\\1\\s\\src\\Service.Tests.Functional\\Service.Tests.Functional.csproj', 'C:\\__w\\1\\s\\src\\Service.Tests.Integration\\Service.Tests.Integration.csproj' ]

Aditional info

Account: msazure/One Pool: OneBranchPipelines on 1ES Hosted Pool

Task definition:

- task: DotNetCoreCLI@2
  displayName: 'Run tests'
  inputs:
    command: test
    projects: '$(RepoRoot)\src\**\*.Tests.*.csproj'
    arguments: '--no-restore --no-build --configuration ${{ parameters.configuration }} --settings $(RepoRoot)\.runsettings --filter TestCategory!=Integration --blame --collect "Code coverage" --logger "trx" --results-directory $(Agent.TempDirectory)\TestResults\ /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura /p:CoverletOutput=$(Agent.TempDirectory)\TestResults\'
    publishTestResults: false

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 5
  • Comments: 22 (7 by maintainers)

Most upvoted comments

I am seeing a similar problem. It appears to be that --collect “Code coverage” sometimes gets parsed incorrectly and “coverage” ends up as a separate parameter that is interpreted as a second project. Below are the msbuild commands output with detailed verbosity enabled (irrelevant parameters removed):

Successful build:

C:\__t\dotnet\sdk\6.0.412\MSBuild.dll
...
-property:VSTestCollect="Code coverage"
C:\__w\1\s\MySolution.sln

Failed build:

c:\__t\dotnet\sdk\6.0.412\MSBuild.dll 
...
-property:VSTestCollect="Code" 
C:\__w\1\s\MySolution.sln
coverage 

Failures happen seemingly at random with no code changes so I’m a bit perplexed as to what could be causing “Code coverage” to be parsed incorrectly

We are seeing this happen in many pipelines in dev.azure.com/microsoft tenant as well. The logging from the task seems to indicate that the issue is actually in the dotnet test code as the commandline that is logged for the dotnet test command appears correct, but the subsequent (transformed) commandline that runs msbuild is where the parsing error has occurred.

We have tried multiple different options for passing in the --collect argument, none of which have been consistently successful. {--collect:"Code coverage"; --collect "Code coverage"; etc.}. IMO the bug is in the parsing/transformation when the value is quoted and includes a space, but that is only hypothesis.

We have found another workaround by encoding the space in “Code Coverage” as %20 so that the option is --collect:Code%20coverage

I am seeing a similar problem. It appears to be that --collect “Code coverage” sometimes gets parsed incorrectly and “coverage” ends up as a separate parameter that is interpreted as a second project. Below are the msbuild commands output with detailed verbosity enabled (irrelevant parameters removed):

Successful build:

C:\__t\dotnet\sdk\6.0.412\MSBuild.dll
...
-property:VSTestCollect="Code coverage"
C:\__w\1\s\MySolution.sln

Failed build:

c:\__t\dotnet\sdk\6.0.412\MSBuild.dll 
...
-property:VSTestCollect="Code" 
C:\__w\1\s\MySolution.sln
coverage 

Failures happen seemingly at random with no code changes so I’m a bit perplexed as to what could be causing “Code coverage” to be parsed incorrectly