-
Notifications
You must be signed in to change notification settings - Fork 25.2k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Note requirement to include UseStaticWebAssets in Staging environment #26751
Comments
@guardrex please review |
Hello @KurtP20 ... Interesting! Yes, I just found out that this is a by-design feature 😄. See ... dotnet/aspnetcore#39596 (comment) I'm going to update the metadata and work this guidance into the Blazor Static Files topic, probably with a cross-link in the Blazor Environments topic. UPDATE: Ok, all set. I'll get to this soon. I should be able to get it covered sometime this week. Thanks for the report! |
I'm going to take a closer look when I get back to this, but try it this way when using Minimal APIs (6.0 or later) ... if (builder.Environment.IsEnvironment("Staging"))
{
StaticWebAssetsLoader.UseStaticWebAssets(builder.Environment, builder.Configuration);
}
Still tho ... what you did seems right. I'll need to investigate |
Thanks for updating the documentation! In the .net 5 template I don't see right away where to include your code. But now I better understand the "side effects" and the reason of having to use |
I found this in a discussion for 5.0 apps ... .ConfigureAppConfiguration((ctx, cb) => {
if (ctx.HostingEnvironment.IsStaging()) {
StaticWebAssetsLoader.UseStaticWebAssets(ctx.HostingEnvironment, ctx.Configuration);
}
}) I'm reading the full discussion at ... |
Looks like this ... builder.WebHost.UseStaticWebAssets(); ... should work for 7.0 or later. Confirmed! ... That seems to work fine in 7.0.
builder.WebHost.UseWebRoot("wwwroot").UseStaticWebAssets();
Ah! The fix was backported to 6.0 in dotnet/aspnetcore#41182, so ... builder.WebHost.UseStaticWebAssets(); ... works in both 6.0 and 7.0. When I get the PR put together, I'll ping Safia to look and confirm that I have the guidance correct. |
... and in 5.0 it is
Your suggestion
does not work for me as parameter 1 cannot be converted from |
Well, it wasn't my suggestion 😄 ... it was in the discussion remarks. Yes, that's right about the param. I did note it in passing. One my personal problems here is that I just set up a brand new PC, and I didn't get it set up with 5.0 hoping that I wouldn't need to. I'd rarely use it, as we're heading into 7.0 at this point. I may fire up the old PC to see what's what. I'll try to work up the PR today. Let me see what's what with the schedule today, but I think I can knock this out first thing 🤞. |
I didn't really copy it exactly. They actually have ... var builder = WebApplication.CreateBuilder(args);
builder.WebHost.ConfigureAppConfiguration((ctx, cb) => {
if (ctx.HostingEnvironment.IsStaging()) {
StaticWebAssetsLoader.UseStaticWebAssets(ctx.HostingEnvironment, ctx.Configuration);
}
}); ... and they claim that that works in 5.0. I'm just going by the discussion given my current lack of 5.0 on this shiny new 💻. |
I would not want to install 5.0 on a new machine either. It's just so much work to change from the 5 to the 6 template where app configuration is much different. The solution with |
I can keep the default. It's just that I don't like cluttering my machine with hundreds of megs of (mostly) dead files 💀 ... 5.0, it's so 2021! 😆 |
[EDIT by guardrex to change the metadata]
I bumped into a nasty error when switching from Devlopment so Staging environment: In Staging, static web assests (e.g. site.css and other java scripts) are not served automatically. You can try this by making a new Blazor Server Side App, switch to Staging and you will see, that site.css is not loaded.
The fix seems to be to include
UseStaticWebAssets
. Unfortunately, it took me quite a while to figure out where to include this, so a code example would be useful. I work off the .net 5 template, so inProgram.cs
I addedHost.ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStaticWebAssets(); webBuilder.UseStartup<Startup>(); })
I also did not find a description of the side effects when including
UseStaticWebAssets
in all environments and I don't know how to access the Environment inConfigureWebHostDefaults
.I think it would be good to mention/highlight the need to include
UseStaticWebAssets
on this page in the documentation and also in the xml documentation ofConfigureWebHostDefaults
, as it mentions that static assets are included, but does not mention that this is only in development environment.Please also elaborate on the side effect of using
UseStaticWebAssets
in all environments in the api documentation page.Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
The text was updated successfully, but these errors were encountered: