1

I have a problem similar to the one outlined in this question.

When using custom environments while running locally, some files are not being loading (resulting in 404s, etc).

Question: How can I call .UseStaticWebAssets() using the WebApplicationBuilder?

In my program.cs, I tried adding some code to call .UseStaticWebAssets() like below, but I'm seeing the error ConfigureWebHost() is not supported by WebApplicationBuilder.Host. Use the WebApplication returned by WebApplicationBuilder.Build() instead.

// program.cs
public static void Main(string[] args)
{
    var builder = WebApplication.CreateBuilder(args);
    builder.Host.ConfigureWebHostDefaults(builder => 
    {
        builder.UseStaticWebAssets();
    });

    // etc...
}

If I try using the WebHost prop on the aforementioned builder, I see compiler errors when trying to call the UseStaticWebAssets() method.

derekbaker783
  • 8,109
  • 4
  • 36
  • 50
  • 1
    Do you need to use the dotnet 6 style minimal hosting model? Have you tried using the previous generic host style? [link](https://learn.microsoft.com/en-us/aspnet/core/migration/50-to-60?view=aspnetcore-6.0&tabs=visual-studio#apps-migrating-to-60-dont-need-to-use-the-new-minimal-hosting-model) – chadnt Apr 25 '22 at 19:09
  • @chadnt, if possible, I'd prefer to use the dotnet 6 minimal style. – derekbaker783 Apr 25 '22 at 19:30

1 Answers1

5

I faced the same issue, and found a workaround here. Basically this gets around the exception; seems like this will be fixed in .NET 7.

builder.WebHost.UseWebRoot("wwwroot").UseStaticWebAssets();

Good luck!

domino
  • 66
  • 2