Skip to content

UseElectron Incorrectly Changes Host Configuration When wwwroot Directory Exists #1050

@AeonSake

Description

@AeonSake

The UseElectron method applied to a WebApplicationBuilder changes the host configuration (content root of WebHost) which is not allowed. This issue comes up whenever the wwwroot directory exists when the application is started; which is an issue when working with pre-/post-build actions that copy stuff into the wwwroot directory (e.g., copying assets or build artifacts from another stage).

// check for the content folder if its exists in base director otherwise no need to include
// It was used before because we are publishing the project which copies everything to bin folder and contentroot wwwroot was folder there.
// now we have implemented the live reload if app is run using /watch then we need to use the default project path.
if (Directory.Exists($"{AppDomain.CurrentDomain.BaseDirectory}\\wwwroot"))
{
builder = builder.UseContentRoot(AppDomain.CurrentDomain.BaseDirectory)
.UseUrls("http://localhost:" + webPort);
}
else
{
builder = builder.UseUrls("http://localhost:" + webPort);
}

The exception is thrown here:
https://github.com/dotnet/aspnetcore/blob/e0d31d9fb90de374424f555ab58e5bfec86d46e6/src/DefaultBuilder/src/ConfigureWebHostBuilder.cs#L64-L69

Call Stack:

ConfigureWebHostBuilder.UseSetting(string, string?)
HostingAbstractionsWebHostBuilderExtensions.UseContentRoot(this IWebHostBuilder, string)
WebHostBuilderExtensions.UseElectron(this IWebHostBuilder, string[], Func<Task>)
WebApplicationBuilderExtensions.UseElectron(this WebApplicationBuilder, string[], Func<Task>)

Steps to reproduce:

  • Create a new Electron.NET project
  • Build once (to create the Debug/Release paths)
  • Create a folder called wwwroot in the build output directory (e.g., <app>/bin/Debug/net10.0/win-x64)
  • Start the application in debug mode

I'm not sure whether this is also an issue for the final build/package but it is definitely a problem for debugging.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions