Blazor Server Apps packed into a Tool can't find static assets
See original GitHub issueDescribe the bug
When packing an ASP.NET app into a dotnet tool package the static assets from wwwroot result in 404.
To Reproduce
- Check out repo
cd DotnetToolStaticFilesNotFound
dotnet pack
dotnet tool install -g --add-source .\bin\Debug\ DotnetToolStaticFilesNotFound
cd ..
- change directory so the wwwroot isn’t in your current path- Load
localhost:5000
in a browser. No css can be found.
Alternately:
- Create a new Blazor server app.
- add
<PackAsTool>true</PackAsTool>
and<IsPackable>true</IsPackable>
to the csproj. - Pack, install and run tool as above.
https://github.com/gfs/BlazorPackFailure
Exceptions (if any)
Further technical details
- Include the output of
dotnet --info
- 7.0.100-rc.2.22477.23
- The IDE (VS / VS Code/ VS4Mac) you’re running on, and its version
- VS 2022 Preview
Also reproduces on .NET 6.0.
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:6 (2 by maintainers)
Top Results From Across the Web
ASP.NET Core Blazor static files
Learn how to configure and manage static files for Blazor apps.
Read more >Why ASP.NET Core web application does not serve static ...
The reason why you found it is not working is because there is no static assets in bin/Debug folder. It works in development...
Read more >How to Build and Secure Web Applications with Blazor
Learn how to build client-side Web apps using Blazor and how to secure them with Auth0 authentication and authorization features.
Read more >ASP.NET hosted blazor WASM not serving static files as ...
I have a Blazor WASM that's configured to be asp.net core (.net 5) hosted. The Blazor client app works just fine, but I...
Read more >Getting Started with Blazor TextBox Component
This section briefly explains about how to include Blazor TextBox component in your Blazor Server App and Blazor WebAssembly App using Visual Studio....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I’ve found a workaround for my case mentioned above that is quite horrible and will bite me in the future, but I can at least move forward. Posting case anyone comes to the same situation:
dotnet publish
to expose them in the publishedwwwroot
folderwwwroot
folder (manually, using file explorer and IDE) since I know that what is in it will be included in the package. Unfortunately I’ll need to update them any time I update the package, which will be a PITA to remember. I’ve also moved them into awwwroot\MudBlazor
instead of the expectedwwwroot\_content\Mudblazor
folder. If this ever get’s fixed, the_content
will eventually appear in the package, and the awkwaredness may remind me of the situation._Host.cshtml
/Layout.cshtml
with the new paths to the asset filesProgram.cs
:GetAssetLocations
as a static method returning a tuple of the calculated pathsbuilder.Environment
’sWebRootPath
andContentRootPath
with the calculated paths:StaticWebAssetsLoader.UseStaticWebAssets(builder.Environment, builder.Configuration);?
from the default template, tooIf anyone else has the same issue, I have figured out a workaround based on the folder structure of the tool when unpacked.