Description
Microsoft.AspNetCore.TestHost.WebHostBuilderExtensions.UseSolutionRelativeContentRoot(this IWebHostBuilder builder, string solutionRelativePath, string applicationBasePath, string solutionName = "*.sln"), in aspnetcore/src/Hosting/TestHost/src/WebHostBuilderExtensions.cs, in the main branch and in latest v6.0.0-preview.4.21253.5 contains the following code:
var directoryInfo = new DirectoryInfo(applicationBasePath);
do {
...
directoryInfo = directoryInfo.Parent;
} while (directoryInfo!.Parent != null);
If the solution file is in the root directory (e.g., E:\solution.sln or \server\share\solution.sln), and if applicationBasePath points to a subfolder (E:\subfolder or E:\sub1\sub2...), the solution file won't be found because the above loop will exit at (directoryInfo!.Parent != null) since the parent of the root directory is always null.
I am not providing a test case as it requires a file in the root directory on the file system, and I am not sure what your policies are in this respect.
However, I believe the bug is pretty obvious. I also verified it with my own project.
To fix the issue, the loop condition should be as follows:
} while (directoryInfo is not null);