Background and Motivation
From @kimsey0 in issue #61304
WebApplicationFactory tries setting the content root based on a number of sources (a builder setting, MvcTestingAppManifest.json, and the assembly metadata) before falling back to setting a solution-relative content root. This looks specifically for a .sln file, which means any test that relies on it breaks when migrating to the new SLNX solution format.
A proposed implementation can be found here: #61305
Proposed API
namespace Microsoft.AspNetCore.TestHost;
public static class WebHostBuilderExtensions
{
- public static Microsoft.AspNetCore.Hosting.IWebHostBuilder UseSolutionRelativeContentRoot(this Microsoft.AspNetCore.Hosting.IWebHostBuilder builder, string solutionRelativePath, string solutionName = "*.sln");
- public static Microsoft.AspNetCore.Hosting.IWebHostBuilder UseSolutionRelativeContentRoot(this Microsoft.AspNetCore.Hosting.IWebHostBuilder builder, string solutionRelativePath, string applicationBasePath, string solutionName = "*.sln");
+ public static Microsoft.AspNetCore.Hosting.IWebHostBuilder UseSolutionRelativeContentRoot(this Microsoft.AspNetCore.Hosting.IWebHostBuilder builder, string solutionRelativePath);
+ public static Microsoft.AspNetCore.Hosting.IWebHostBuilder UseSolutionRelativeContentRoot(this Microsoft.AspNetCore.Hosting.IWebHostBuilder builder, string solutionRelativePath, string solutionName);
+ public static Microsoft.AspNetCore.Hosting.IWebHostBuilder UseSolutionRelativeContentRoot(this Microsoft.AspNetCore.Hosting.IWebHostBuilder builder, string solutionRelativePath, string applicationBasePath, string solutionName);
+ public static Microsoft.AspNetCore.Hosting.IWebHostBuilder UseSolutionRelativeContentRoot(this Microsoft.AspNetCore.Hosting.IWebHostBuilder builder, string solutionRelativePath, string applicationBasePath, System.ReadOnlySpan<string> solutionNames = default(System.ReadOnlySpan<string>));
}
Usage Examples
before:
.UseSolutionRelativeContentRoot(Path.Combine("test", "WebSites", applicationName), "*.slnx")
after:
.UseSolutionRelativeContentRoot(Path.Combine("test", "WebSites", applicationName))
Alternative Designs
The solutionNames overload may be more appropriately take a IReadOnlyCollection<string> given that this api is called on a builder that is typical a one-time setup, so performance isn't particularly critical.
namespace Microsoft.AspNetCore.TestHost;
public static class WebHostBuilderExtensions
{
+ public static Microsoft.AspNetCore.Hosting.IWebHostBuilder UseSolutionRelativeContentRoot(this Microsoft.AspNetCore.Hosting.IWebHostBuilder builder, string solutionRelativePath, string applicationBasePath, System.Collections.Generic.IReadOnlyCollection<string> solutionNames = default(System.Collections.Generic.IReadOnlyCollection<string>));
}
Risks
While these changes should be binary and source compatible, we should double-check this.
Background and Motivation
From @kimsey0 in issue #61304
WebApplicationFactory tries setting the content root based on a number of sources (a builder setting, MvcTestingAppManifest.json, and the assembly metadata) before falling back to setting a solution-relative content root. This looks specifically for a .sln file, which means any test that relies on it breaks when migrating to the new SLNX solution format.
A proposed implementation can be found here: #61305
Proposed API
namespace Microsoft.AspNetCore.TestHost; public static class WebHostBuilderExtensions { - public static Microsoft.AspNetCore.Hosting.IWebHostBuilder UseSolutionRelativeContentRoot(this Microsoft.AspNetCore.Hosting.IWebHostBuilder builder, string solutionRelativePath, string solutionName = "*.sln"); - public static Microsoft.AspNetCore.Hosting.IWebHostBuilder UseSolutionRelativeContentRoot(this Microsoft.AspNetCore.Hosting.IWebHostBuilder builder, string solutionRelativePath, string applicationBasePath, string solutionName = "*.sln"); + public static Microsoft.AspNetCore.Hosting.IWebHostBuilder UseSolutionRelativeContentRoot(this Microsoft.AspNetCore.Hosting.IWebHostBuilder builder, string solutionRelativePath); + public static Microsoft.AspNetCore.Hosting.IWebHostBuilder UseSolutionRelativeContentRoot(this Microsoft.AspNetCore.Hosting.IWebHostBuilder builder, string solutionRelativePath, string solutionName); + public static Microsoft.AspNetCore.Hosting.IWebHostBuilder UseSolutionRelativeContentRoot(this Microsoft.AspNetCore.Hosting.IWebHostBuilder builder, string solutionRelativePath, string applicationBasePath, string solutionName); + public static Microsoft.AspNetCore.Hosting.IWebHostBuilder UseSolutionRelativeContentRoot(this Microsoft.AspNetCore.Hosting.IWebHostBuilder builder, string solutionRelativePath, string applicationBasePath, System.ReadOnlySpan<string> solutionNames = default(System.ReadOnlySpan<string>)); }Usage Examples
before:
after:
Alternative Designs
The
solutionNamesoverload may be more appropriately take aIReadOnlyCollection<string>given that this api is called on a builder that is typical a one-time setup, so performance isn't particularly critical.namespace Microsoft.AspNetCore.TestHost; public static class WebHostBuilderExtensions { + public static Microsoft.AspNetCore.Hosting.IWebHostBuilder UseSolutionRelativeContentRoot(this Microsoft.AspNetCore.Hosting.IWebHostBuilder builder, string solutionRelativePath, string applicationBasePath, System.Collections.Generic.IReadOnlyCollection<string> solutionNames = default(System.Collections.Generic.IReadOnlyCollection<string>)); }Risks
While these changes should be binary and source compatible, we should double-check this.