I’m starting a new .Net 8 Blazor application.
When I run the dotnet publish -c Release
command and start the published application I get a 404 error for my css file. This doesn’t happen when I developing (using the dotnet watch
or dotnet run
).
Here you can see it works on the dotnet run
command
This is the error I am running into
Any help would be appreciated!
I’ve tried starting a new application in the hopes that I accidentally passed some arguments wrong.
edit:
Here are the steps to reproduce the error:
- in your terminal run
dotnet new blazor -o ./Blazor.Host
- run
cd ./Blazor.Host
- run
dotnet publish
- run
dotnet path/to/app/Blazor.Host.dll
It doesn’t look like any of the static files are getting served
Zaid Masri is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
3
I also reproduce issue in .net8 when adding path when using dotnet
dll command. And it has the StaticFileMiddleware warning like below.
You could try replace the staticFiles middleware like below to solve the problem
app.UseStaticFiles(new StaticFileOptions
{
FileProvider = new PhysicalFileProvider(Path.Combine(System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location), "wwwroot")),
RequestPath = ""
});
Additionally, this problem has been disappeared in .Net9 template which uses app.MapStaticAssets();