New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WebApplicationOptions.WebRootPath is ignored if a wwwroot folder exists #40613
Comments
That's what should be happening now. Here's the code that defaults to 'wwwroot':
As you can see it should only be setting it to 'wwwroot' if options.WebRoot is null. If this doesn't match what you're seeing, please share a minimal repro app on GitHub and we'll take a look. |
Here is an ultra-minimal repro that demonstrates the problem: https://github.com/space-alien/AspNetWebRootPath |
@space-alien Thank you for providing that. I took a look and your description of the behavior is right. It looks like something in the static asset manifest generation logic is eagerly matching wwwroot if it exists. I can see that when the wwwroot directory is present, it gets added to the beginning of @javiercn Can you please take a look and/or reroute this issue? |
@adityamandaleeka will take a look. |
@space-alien The content from the wwwroot is served because those files are considered static web assets. If you want to change where the files are being served from to avoid this you have several options:
Alternatively, if you provide a bit more details on your scenario, I might be able to suggest alternative options that might be simpler to accomplish the same goal. |
Hi @space-alien. We have added the "Needs: Author Feedback" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time. |
@javiercn Thank you for your reply, Javier. I have found a workaround in my project, but I think the question is whether the current behaviour is desirable or intuitive. It certainly cost me a lot of time. My repro demonstrates how even though I would expect the |
What's happening here is that there are two features that are not interacting great together in this scenario. Each feature is doing what it is supposed to do. None of the features have specific knowledge of where you are serving the files from, they both have a convention that by default looks at the wwwroot folder. One of them does it at compile time (static web assets) and the other one at runtime (WebRootPath). At the base layer, IWebHostEnvironment offers a convention that defines where files are served from (which defaults to wwwroot) at runtime, which is used during publish. However since a few releases ago, we have another feature that builds on top and takes control over how assets are served during development (which is static web assets), so if you want to change where files are served from during development, you need to either disable the feature (which breaks content from razor class libraries) or update the configuration in static web assets to reflect your convention. Static web assets when enabled are responsible for defining the content for the app at build and publish time, so they need to be in control, during development, to offer a coherent view between the assets being served during development and the assets being served in production. I understand in your case it might not match your expectations, but the alternative might result in other unexpected behaviors that are really hard to debug in much more common scenarios (where the two features are using the conventions), so I think the behavior here is expected and by design. It might be worth for us updating the documentation to cover this case. That said, I would like to understand more about your scenario, since there are likely other alternative ways to achieve the same result that might require less tunning. |
Hi @space-alien. We have added the "Needs: Author Feedback" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time. |
* remove .yarn folder from dockerignore * add InvariantGlobalization false https://docs.microsoft.com/en-us/answers/questions/728280/running-net-6-project-in-docker-throws-globalizati.html * remove staticwebassets.runtime.json after build dotnet/aspnetcore#40613
* remove .yarn folder from dockerignore * add InvariantGlobalization false https://docs.microsoft.com/en-us/answers/questions/728280/running-net-6-project-in-docker-throws-globalizati.html * remove staticwebassets.runtime.json after build dotnet/aspnetcore#40613
This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment. If it is closed, feel free to comment when you are able to provide the additional information and we will re-investigate. See our Issue Management Policies for more information. |
@javiercn Thanks Javier. I have avoided the issue in my project by forcing the production assets into a subfolder of Yes, I agree that perhaps updating the documentation to cover this behaviour might be helpful for other users. |
Filed dotnet/AspNetCore.Docs#25446 to improve the docs for this scenario. |
Is there an existing issue for this?
Describe the bug
If a
wwwroot
folder exists, content is served from that location even thoughWebApplicationOptions.WebRootPath
has been specified.In my development environment, I want to serve my web app from uncompiled sources. In production, my web app is compiled into the
wwwroot
folder. I switch the web root path on the development environment variable as shown below. (This is the only way I could find in .NET 6, whereas before it was trivial to set theIWebHostEnvironment.WebRootPath
property).I am now forced to rename the production
wwwroot
folder to something else, in order to circumvent this default behaviour.Expected Behavior
I expect the
WebApplicationOptions.WebRootPath
property to always take precedence even when there is a defaultwwwroot
folder on disk.I also wish there were a way to set this property after instantiating the
WebApplicationBuilder
.Steps To Reproduce
No response
Exceptions (if any)
No response
.NET Version
6.0.200
Anything else?
No response
The text was updated successfully, but these errors were encountered: