azure-pipelines-tasks: DotNetCoreCLI@2 test does not use enhanced reporting for compile errors

When using DotNetCoreCLI@2 in test command mode you have an implicit restore/build step, if your build fails you will not get enhanced error logging in the build logs.

It is believed that this is due to failing to register the MSBuild Logger in cases that are not explicitly a build as seen here: https://github.com/microsoft/azure-pipelines-tasks/blob/d8dd6802ce09fb65edc656e6625df3e0f92e592d/Tasks/DotNetCoreCLIV2/dotnetcore.ts#L109-L112

Required Information

Question, Bug, or Feature?
Type: Bug

Enter Task Name: DotNetCoreCLI@2

Environment

  • Server - Azure Pipelines
  • Agent - Hosted
Pool: Azure Pipelines
Image: ubuntu-latest
Agent: Hosted Agent

Issue Description / Repro Steps

Consider the following:

azure-pipelines.yml

steps:
  - task: DotNetCoreCLI@2
    displayName: 'dotnet test'
    inputs:
      command: 'test'
      projects: '**/Test.csproj'
      arguments: '/p:CollectCoverage=true /p:CoverletOutputFormat=cobertura /p:CoverletOutput=./coverage/'
      publishTestResults: true

Test.csproj

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>net6.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
    <IsPackable>false</IsPackable>
    <EnableNETAnalyzers>True</EnableNETAnalyzers>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="6.0.0">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
    <PackageReference Include="MSTest.TestAdapter" Version="2.2.8" />
    <PackageReference Include="MSTest.TestFramework" Version="2.2.8" />
    <PackageReference Include="coverlet.msbuild" Version="3.1.2">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="coverlet.collector" Version="3.1.2">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
  </ItemGroup>

</Project>

UnitTest1.cs

namespace DotNetCoreCLI_Bugs
{
    using Microsoft.VisualStudio.TestTools.UnitTesting;

    [TestClass]
    public class UnitTest1
    {
        [TestMethod]
        public void TestMethod1()
        {
            Random random = new Random();
            random.Next(); //Trigger CA5394
            Assert.AreEqual(true, true);
        }
    }
}

.editorconfig

[*.{cs,vb}]
dotnet_diagnostic.CA5394.severity = error

The above is a bare bones project that creates an MSTest based unit test that will trigger CA5394 and a bare bones YAML based pipeline that will attempt to invoke this using the DotNetCoreCLI@2 using the test command.

When running this in a private Azure DevOps Project I see the following:

image

At least it shows that it fails but it doesn’t say why without digging into the verbose logs; even then it is not highlighted in red (I have boxed the first instance of the error in red):

image

Compare this to when you use build command (using this YAML):

steps:
  - task: DotNetCoreCLI@2
    displayName: 'dotnet build'
    inputs:
      command: 'build'
      projects: '**/Test.csproj'

You are shown right on the build summary page the error: image

Along with on the detailed log this is kicked out:

image

It is believed that this is because the custom MSBuild Logger is being registered by the task when build is selected as indicated in the summary.

The behavior, in my opinion, should be identical in all cases for the best UX.

About this issue

  • Original URL
  • State: open
  • Created 4 years ago
  • Reactions: 3
  • Comments: 19 (4 by maintainers)

Most upvoted comments

Lol @aolszowka if anything, I love that this issue gives us a periodic opportunity to catch up 😃 I’ll try to ping some folks internally to see if we can get attention to this issue.

This issue is stale because it has been open for 180 days with no activity. Remove the stale label or comment on the issue otherwise this will be closed in 5 days

The issue is still outstanding and therefore not stale, its unclear if the Team has even triaged this?

This issue is stale because it has been open for 180 days with no activity. Remove the stale label or comment on the issue otherwise this will be closed in 5 days

Hi all, hope you’re doing well, the industry continues to be difficult for all of us. I hope all of us continue to find meaningful employment that provides for us and our families. @KirillOsenkov still doing great things in the MSBuild world?

I have updated the project to .NET 8 (the latest that ubuntu-latest supports via the pipelines) and we’re still seeing the issue as described in the original post. Again happy to add anyone to the playground:

Image

Here’s the updated Test.csproj:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>net8.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
    <IsPackable>false</IsPackable>
    <EnableNETAnalyzers>True</EnableNETAnalyzers>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="9.0.0">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
    <PackageReference Include="MSTest.TestAdapter" Version="3.9.1" />
    <PackageReference Include="MSTest.TestFramework" Version="3.9.1" />
    <PackageReference Include="coverlet.msbuild" Version="6.0.4">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    <PackageReference Include="coverlet.collector" Version="6.0.4">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
  </ItemGroup>

</Project>

Hey There… Been Awhile…

This is still failing; I’ve got this in my Azure DevOps Playground Instance, I’d be more than happy to share this if it would get this addressed.

Here’s a screenshot from today: image

I get priorities are hard, layoffs, restructuring, attempting to do yet another issue reporting system to paper over the huge backlog yet again, etc…

While I’m here I might as well give another shout to one of my all time favorite developers (next to Raymond Chen) @KirillOsenkov hope all is well on that end, you are not recognized enough 😉

Good to see you again @KirillOsenkov maybe some of my outstanding bugs will get resolved or observed finally! Hope all is well on your end 😃

Ah, nevermind… I once again lost hope in this task, as it does some black magic modifying the output paths I specify… I think we need V3 tasks for .NET… Some that would not do such unexpected and unwanted things like appending things to the output path…

As for the workaround, I found where the DLL is located (not in NPM package after all):

https://github.com/microsoft/azure-pipelines-tasks/blob/cccb1c6abdf27c119fc664fc963bc918039c00db/Tasks/DotNetCoreCLIV2/make.json#L5

So guess we can download this ZIP file (the link has not changed for almost three years now), extract the DLL and append the -dl param ourselves…

We’d use it somehow like this:

dotnet publish -dl:CentralLogger,"LOGGER_PATH"*ForwardingLogger,"LOGGER_PATH"

I’m not gonna try this myself now - it’s not verified it will work, and of course, it’s not good to rely on some random link. One would need to do at least a proper error handling in case the link does not work anymore…