4

This question is like one posted a year ago titled xUnit tests run locally but not on Azure DevOps. However, it is different enough to warrant a separate question. I'm developing an ASP.NET MVC project using .NET 6. And I've got an Azure CI Pipeline which uses DotNetCoreCLI@2, instead of the VSTest@2 task in the pipeline, as is normally included when using the Azure Pipeline ASP.NET template. When running the pipeline I get this warning message in the log:

D:\a\1\s\PharmacyWarehouseV2\PharmacyWarehouseV2.Test\HomeControllerTest.cs(18,49): warning CS8625: Cannot convert null literal to non-nullable reference type.

Looking at the xUnit test (there's only one) it's easy to see why it's doing this:

var controller = new HomeController(null);

At the time I was mainly interested in getting a unit test working. Now I'm thinking that the reason why it isn't working is because the C# compiler sees that NULL being passed into the HomeController where it would be assigned to the ILogger. Therefore, I started looking for a better way of logging. I came across another reference, which I cannot find again (unfortunately) saying that .NET 6 doesn't work with the ILogger anymore. So, what is the preferred way of handling logging now with .NET 6, both in a MVC controller and in a xUnit unit test?

Here's the DotNetCoreCLI@2 task in my YAML file:

- task: DotNetCoreCLI@2
  displayName: 'Dot Net Core Test'
  inputs:
    command: 'test'
    projects: '**/*[Tt]est*/*.csproj'
    arguments: '--configuration $(BuildConfiguration)'
  enabled: false
Rod
  • 4,107
  • 12
  • 57
  • 81
  • @Leo-liu-msft wondering what your comments might be on this? – Rod Mar 15 '22 at 16:01
  • I found the link mentioning that .NET 6 doesn't work the same way with ILogger. https://learn.microsoft.com/en-us/dotnet/core/extensions/logging?tabs=command-line – Rod Mar 15 '22 at 19:21

0 Answers0