'dotnet run not serving static assets of dependencies

I have a problem with dotnet run and static assets (contentFiles). I have a nuget package (built in my CI) that only contains CSS files to be used in other projects.

The 'other project' I'm talking about is a blazorwasm app that should use these css styles. The problem I have is:

  • when I start the blazorwasm app with dotnet run (which starts a Kestrel Server to serve the compiles files I suppose?) the content Files of the nuget with the CSS are not served and lead to a 404 (referred by "css/theme.min.css").

  • when I use 'dotnet publish' and start a nginx docker to serve it, the files are server (and stored at wwwroot/css of course)

Since I always used dotnet run to test my blazor apps before - and never had such a problem - I am a bit puzzled.

The nuspec of the nuget package is:

<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd" >
  <metadata minClientVersion="3.3">
    <id>WebTheme</id>
    <title>Web Theme</title>
    <version>0.1.10</version>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <copyright>Copyright 2022</copyright>
    <contentFiles>
      <files include="any/any/wwwroot/css/*" buildAction="Content" copyToOutput="true" flatten="false"/>
    </contentFiles>
  </metadata>
  <files>
    <file src="dist/css/theme.css" target="contentFiles/any/any/wwwroot/css" />
    <file src="dist/css/theme.css.map" target="contentFiles/any/any/wwwroot/css" />
    <file src="dist/css/theme.min.css" target="contentFiles/any/any/wwwroot/css" />
    <file src="dist/css/theme.min.css.map" target="contentFiles/any/any/wwwroot/css" />
    <file src="dist/css/theme.css" target="content/wwwroot/css" />
    <file src="dist/css/theme.css.map" target="content/wwwroot/css" />
    <file src="dist/css/theme.min.css" target="content/wwwroot/css" />
    <file src="dist/css/theme.min.css.map" target="content/wwwroot/css" />
  </files>
</package>

Program.cs of the target application:

using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Components.WebAssembly.Authentication;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using ManagementApp;
using Microsoft.Extensions.Options;

var builder = WebAssemblyHostBuilder.CreateDefault(args);

builder.RootComponents.Add<App>("#app");
builder.RootComponents.Add<HeadOutlet>("head::after");

builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });

builder.Services.AddOptions();

await builder.Build().RunAsync();


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source