dotnet / aspnetcore Public
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
Blazor WASM not loading appsettings.{environment}.json in Azure App Services #25152
Comments
Thanks for contacting us. This may be potentially related to another reported issue: #21992 |
Thanks for contacting us. |
We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process. |
I'm curious why this is considered minor severity and has been pushed from Next sprint planning? This is a pretty major issue and a deviation from how everything else in the .NET Core ecosystem works. It also makes managing configuration across environments very difficult. We have to manually edit appSettings.json to match the environment we're about to deploy to every single time we need to do a deployment. I'm surprised that this issue hasn't been reported frequently. Am I missing something? |
We solved it like this:
|
@trygvelo Thanks - will give this a try |
I am also having this exact issue when hosting inside an nginx container. I can see that the ASPNETCORE_ENVIRONMENT variable is set correctly, and that the files are present. However, only appsettings.json is ever loaded. The script above will not work for my use-case, as I feed the variable through from an azure-pipeline script. |
This got resolved by using Pascal Case ASPNETCORE_ENVIRONMENT=Dev , ASPNETCORE_ENVIRONMENT=Production |
I'm not sure what you mean, we have the configuration in uppercase and it's not working, |
Any update on progress on this feature? |
Any updates on this? Not sure how this could be treated as a minor issue!!! The entire development and debugging (via visual studio) works just fine and it blasts out on the very first deployment (I'm using docker with Nginx as the server). While it is logical to think that "Environment Variable" does not make sense for a static website application, it is very sad that no proper warning is provided in the MSDN - https://docs.microsoft.com/en-us/aspnet/core/blazor/fundamentals/configuration?view=aspnetcore-5.0 From the source code, it is evident that app settings transformation will work ONLY for ASPNET hosted WASM apps, and for the rest of others, it will default to "Production":
UPDATE - My Workaround As I'm deploying the Blazor wasm in a Linux container (as Nginx as the server), I did the config "transform" during the build process. Updated docker file (pasting only relevant parts):
And during Docker build, pass the argument BUILD_ENVIRONMENT=<your_enviornment_name_matching_the_env_json> |
I'd love to see updates on this, as well. I see the "affected-very-few" label, but I feel like there is a fundamental and subtle issue with appsettings and non-dotnet blazorwasm hosts. |
It seems it is not only an Azure problem, the same problem occurs on local machines as well. I followed the instructions told in https://docs.microsoft.com/en-us/aspnet/core/fundamentals/environments?view=aspnetcore-5.0 and then I do receive a HTTP 404 Not Found error message, Blazor WASM does not start at all. It seems it only works with one single or only in specific environments. The problem was also discussed here: #21992 - The answer was there that the problem will not be fixed in the near future by Microsoft. But in companies, multiple environments are often needed, e.g. if the same Blazor WASM shall e.g. run in two different production environments with different app settings. I would also love to have multiple environment support in Blazor WASM as soon as possible. |
Same problem here, Microsoft wtf do you wanna fix that ?! |
Blazor WASM can't read the Environment variables. MS has two documented options here, https://docs.microsoft.com/en-us/aspnet/core/blazor/fundamentals/environments?view=aspnetcore-5.0 I'm using the web.config approach and have my ci/cd pipeline replace the environment on build. |
Kudos to @trygvelo for such a creative answer, even if it only works for WebAssembly deployments from Visual Studio. It feels dirty and I can't say I like it, but it did work for me using .NET 5 with a few tweaks that I'll describe for others. As mentioned, I added a Pre-build event, but with a minor directory change (removing '\js' from the directory path):
If you do not do this, then all calls to the IsDevelopment() and IsProduction() methods will always return false. i.e.
I did this because it seemed like the inheritance of values from appsettings.json to, say, appsettings.Production.json was not working correctly. In other words, when I had settings in both files, I believe I was getting the original configuration values from appsettings.json instead of the environment-specific ones. Transferring all DEV/Debug values from appsettings.json to the appsettings.Development.json file seemed to work best.
The output from this can simply be displayed in a razor page as such:
As you can guess, this was a big, frustrating, time sink and I have a hard time believing there isn't a better way. But, until I am enlightened by that better way, this will get me (and hopefully you) past the issue. |
It's not only a problem of WASM and Azure. I've been running into the same bug on my local Blazor server app with IISExpress. Everything worked fine when I had set |
I reported this back in reported this in May of 2020 #21992 and it is still a lingering issues in .net Core 3.1, .net 5 and potentially .net 6? We are now a year and a half removed and this is still not fixed. Unless you have 2 environment, it is unthinkable that this could be an acceptable state. Incase anyone would like to know, I was able to work around it by adding a second environment variable I hope that one day this gets solved by the framework. |
Encountered the same issue with dotnet 6.0.100 It's very annoying as I want to change Or I'd like to propose that we can have some note in the docs mentioned above that
|
Hi Knight1219 |
I am having this same issue using .NET 6.0.2. Questions from similar bug:
appsettings.{environment}.json file are being published Please escalate this bug. Note: I am not sure why this bug has a label of "affected-very-few" or "severity-minor". |
"affected-very-few", "severity-minor", ".NET 7 planning" - utterly ridiculous. This is such a fundamental aspect of app configuration and there is no stable workaround. Thanks a bunch Microsoft. |
For ASP.NET Core Hosted Blazor WASM, This is the middleware I created. The
|
@knight1219 your middleware worked for me as well to fix the same issue I was having. My hosted blazor wasm app was published to IIS. The server had the aspnetcore environment variable correctly, but it wasn't being passed down to the client wasm app. I ended up going a slightly different direction though. Correct me if I'm wrong, but the middleware is appending the response header to all responses? I instead let the UseStaticFiles AppBuilder extension append the blazor-environment header to the response serving the blazor.boot.json file only. I was already doing another response header modification to fix another blazor wasm problem with integrity here: #38552 Here is what I went with that combined the environment variable with the caching issue.
|
Agreed, I don't understand how this is minor and very few affected. This makes Blazor WASM unusable in a production environment. Can someone from the team explain how this is a minor issue? What is the recommended method for deploying into multiple environments with the same code? Here is the very hacky workaround that we ended up with in the index.html file we replaced:
with:
|
We switched the standalone WASM application to hosted WASM application and followed the environment approach described in https://docs.microsoft.com/en-us/aspnet/core/blazor/fundamentals/environments?view=aspnetcore-6.0#set-the-environment-for-azure-app-service. |
Same issue. Thought we were missing something, but as it seems it's impossible to resolve, unless you only want to use this during the production environment while deploying. I'm trying to fix it via my deploy pipeline where I modify the name of the appsettings.{environment} to production. |
Same issue here. @CameronVetter 's work-around is working for us, Thank you for sharing it. I did have to make sure it was authentication line below: |
I like @gilm0079 use of the I did see this was added to the .NET 7 preview milestone last month, is there active work being done on this issue? It's been a outstanding issue since Blazor's launch (not sure why my issue was closed #21992 about this.) I would love to tell my Architecture team we don't need an extra environment variable and we can go back to using ASPNETCORE_ENVIRONMENT. It still is a bit hard to understand how this isn't an issue for more people and how the Blazor team doesn't see this as a critical issue. |
Describe the bug
When developing locally (Blazor WASM), I have the following files in /wwwroot:
My launchSettings.json specifies an ASPNETCORE_ENVIRONMENT of "LocalDevelopment".
When running locally, everything works as expected. appsettings.json and appsettings.LocalDevelopment.json are merged as expected.
I have just published the Blazor WASM app to Azure App Services, and appsettings.json merging fails. I have the ASPNETCORE_ENVIRONMENT set to "Development" in the App Service:
I have been able to confirm the failure by putting all of my settings in appsettings.json so that I don't need to rely on merging. The app runs as expected in the App Service.
To Reproduce
1: Create a new Blazor WASM ASP.NET Core Hosted application
2: Add appsettings.json, and appsettings.Development.json to /wwwroot
3: Add a configuration value to both files that requires merging.
4: Locally, set ASPNETCORE_ENVIRONMENT to "Development"
5: Confirm that the correct config value gets read
6: Deploy to Azure App Service
7: Set ASPNETCORE_ENVIRONMENT to "Development" for the App Service
8: BUG: Note that value is not read from appsettings.Development.json. It is read from appsettings.json.
Further technical details
dotnet --info
The text was updated successfully, but these errors were encountered: