Skip to content

UseSolutionRelativeContentRoot overloads to support slnx discovery #63131

@slang25

Description

@slang25

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    api-ready-for-reviewAPI is ready for formal API review - https://github.com/dotnet/apireviewsarea-networkingIncludes servers, yarp, json patch, bedrock, websockets, http client factory, and http abstractionsfeature-mvc-testingMVC testing package

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions