'Azure Pipelines: dotnet test fails after dotnet build with -o - "It was not possible to find any compatible framework version"
Here's what I'm trying to do, running a Pipeline on a self-hosted Agent:
- Install .NET SDK 6.0.202
- Build my Solution to a specific Output Directory:
- task: DotNetCoreCLI@2
inputs:
command: build
projects: MySolution.sln
arguments: "--configuration MyConfiguration -o $(Build.BinariesDirectory)"
- Run (NUnit) Unit tests contained in some of the built DLLs
- task: DotNetCoreCLI@2
inputs:
command: test
projects: |
$(Build.BinariesDirectory)\**\*Tests.dll
However, I get the TestHost exiting with the following error:
It was not possible to find any compatible framework version
The framework 'Microsoft.NETCore.App', version '6.0.0' (x64) was not found.
- No frameworks were found.
- The same thing works, if I leave out the -o parameter and just let each project build in its bin/MyConfiguration folder.
- Locally, everything works fine, with or without the -o, just doing "dotnet test Outfolder/someTests.dll".
- Listing the installed runtimes with dotnet --list-runtimes, shows various runtimes including the wanted 6.0.0.
- Using "where.exe dotnet" shows two installation locations, with the correct one (_work_tool\dotnet\dotnet.exe) showing first. Neither indicates a x86 installation, following advice for some similar problems that pointed to the x86 runtime being falsely used/discovered
- Both the succeeding step without -o and the failing step with -o use the same dotnet.exe
- Getting the agent's OS architecture with "wmic OS get OSArchitecture" returns 64-bit
- I tried explicitly installing the .NET runtime 6.0.0 to no avail.
- Earlier, all projects were configured via .targets file to build to a common output directory. All test projects were configured to build to a different common directory. Build and test were both successful at that point.
- All projects define x64 as Platform, all test projects additionally define PlatformTarget x64
- All projects have net6.0-windows as TargetFramework. I am unsure why it is trying to explicitly use the 6.0.0 runtime instead of a later 6.0.x one.
How do I get my build agent to successfully run my tests when explicitly building to an output directory?
Update
Some new info: Extending the UseDotNet Task with "performMultiLevelLookup: true" replaces "No frameworks were found" with a list of some runtimes found at C:\Program Files (those which are installed globally on the agent I guess).
The issue seems to be that dotnet test does not look for the runtime in the agent working directory (_work_tool\dotnet). PATH does include that path (and ahead of C:\Program Files...), but with a forward slash (C:\agent_work_tool/dotnet) which I am not sure if it is an issue.
Update 2
These issues might be related:
https://github.com/microsoft/vstest/issues/2228
https://github.com/dotnet/runtime/issues/68180
I suspect that the testing task is looking for the runtime in the wrong place, which is why it finds none and some in the default installation location if using performMultiLevelLookup. Why this would happen only if I previously build to a specific output directory though and how to fix it, is puzzling to me.
I tried outputting the DOTNET_ROOT env var at various points throughout the pipeline run. It is set by the UseDotNetTask (to C:\agent\_work\_tool/dotnet) and not changed before or after the testing task. So I guess, either it is set temporarily during the test task, ignored or doesn’t work due to the forward slash. But then: why does it work for dotnet build?
Solution 1:[1]
in our Pipelines running on servers with multiple runtimes, before we use .NET core we always have to include a task like this at the top, give it a try if it makes any difference:
steps:
- task: UseDotNet@2
inputs:
version: '6.0.x'
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Davide Piras |
