It appears that the time has come where we are forced to abandon VSTest and convert to using Microsoft Test Platform (MTP) in our testing applications.
I use Azure DevOps for deploying applications to VMs in Azure. I used YAML files to script out the process. I upgraded my test applications to xunit.v3 NuGet package without having to make any changes to my projects or Azure YAML scripts. However, when I upgraded to xUnit v3 to v4.0, that changed. VSTest is no longer supported with the existing syntax.
I received the following message when the Azure DevOps YAML executed:
##[warning]No test result files were found.
##[error]Dotnet command failed with non-zero exit code on the following projects : [ 'D:\a\1\s\API.Tests' ]
All of this is supported in .NET 10 and up, so not sure you can accomplish any of this in a lower runtime.
These are the steps that I had to take in order to get my Xunit test projects to run under Microsoft Test Platform (MTP).
Step 1
Edit your csproj file for the test application and change:
<OutputType>Library</OutputType>
to
<OutputType>Exe</OutputType>
Step 2
In the same section, add the following lines if they don’t already exist:
<UseMicrosoftTestingPlatformRunner>true</UseMicrosoftTestingPlatformRunner>
<EnableMSTestRunner>true</EnableMSTestRunner>
<EnableMicrosoftTestingExtensionsJUnitReport>true</EnableMicrosoftTestingExtensionsJUnitReport>
Step 3
In the section of your csproj file where dependencies are loaded, see if you have these line, with any versions and remove them. Note that you can do this in the Manage NuGet Packages for Solution option too.
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.9.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.5">
Step 4
Upgrade xunit to version 4.x. Note that you can do this in the Manage NuGet Packages for Solution option too.
<PackageReference Include="xunit.v3" Version="4.0.0" />
Step 5
See if a global.json file exists in the same folder as your solution (sln) file. If not create one. Make sure that it has to following entry:
{
"test": {
"runner": "Microsoft.Testing.Platform"
}
}
Step 6
I have YML (yaml) files for the deployments as part of my projects that run when merged with particular branches. In order to run the new MTP section, I had to run it as a script:
- script: dotnet test {project folder}\{project name}.csproj --configuration $(buildConfiguration) --no-build --results-directory $(Build.ArtifactStagingDirectory)\TestResults --report-xunit-junit
displayName: "Run API Tests"
That should do it.
For reference, this is my old Azure DevOps YAML that stopped working after xunit.v3 v4 was installed:
- task: DotNetCoreCLI@2
displayName: 'Run API Tests'
inputs:
command: 'test'
arguments: '--configuration $(buildConfiguration) --collect:"XPlat Code Coverage" -- DataCollectionRunSettings.DataCollectors.DataCollector.Configuration.Format=cobertura'
publishTestResults: true
projects: '{project name}'
Testing Locally
Once you build, you can test locally by going to the test project bin\debug\net10.0 folder and look for the project.exe. Run that from the command line and you should see the new MTP output which has colors. The old VSTest did not have color output. I sure hope we’re not all having to do this so that we could have color in the output :-).
If you navigate to the same folder as you solution file, you can also execute the dotnet test:
dotnet test C:\{path to solution}\{project name}.csproj --configuration debug --no-build --results-directory C:\Temp\TestResults --report-xunit-junit
Language Folders
When changing the application type to an Exe, we will now get the default language folders in our bin folder after build. You may not be concerned about this, but you if you’d like, you can add this to the project file as well:
<SatelliteResourceLanguages>en-US</SatelliteResourceLanguages>
This will prevent all extraneous folders from being created during the build. This is the same setting used in UI and web-based projects.
References:
Here are the general instructions provided by Microsoft to convert to MTP:
https://learn.microsoft.com/en-us/dotnet/core/testing/migrating-vstest-microsoft-testing-platform

















