Azure Devops UnitTest not finding ".deps.json" file

There were two issues with this Problem:

  1. The found unit test was located in the "/obj/release" folder, but into this folder no *.deps.json files are copied. In the build-task you can see that the *.deps.json were successfully build and copied:

Copying file from "d:\a\1\s\APPNAME\bin\Release\netcoreapp3.1\APPNAME.deps.json" to "d:\a\1\s..."

  1. The second issue I had, was that a reference in the unit test was referencing a .NET Standard 2.1 Solution, which seems not to include any *.deps.json in the output.

Here is my fixed yaml file:

# UnitTests
- task: [email protected]
  displayName: 'Build Test'
    solution: '**/APPNAME.UnitTests.csproj'
    msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation="$(Build.ArtifactStagingDirectory)"'
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'

- task: [email protected]
    testSelector: testAssemblies
    testAssemblyVer2: 'APPNAME\bin\Release\netcoreapp3.1\APPNAME.UnitTests.dll' #Full path to test dll
    testFiltercriteria: FullyQualifiedName~APPNAME.UnitTests # Further namespace filter
    runInParallel: false
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'
    diagnosticsEnabled: true

In addition to ignore the obj folder with !**\obj\**, from .NET 5 we also had to ignore a ref folder inside the bin folder; !**\bin\**\ref\**. Not ignoring this caused 2 files matching UnitTests.dll to be found, and the dll from the ref folder would fail with the error: UnitTests.deps.json file was not found

What is this ref-folder?

Now our test-task looks like this:

- task: [email protected]
    testSelector: 'testAssemblies'
    testAssemblyVer2: |
    searchFolder: '$(System.DefaultWorkingDirectory)'
    runTestsInIsolation: true
    codeCoverageEnabled: true