Maybe just try the example:
https://github.com/HTD/BlazorProfiles
This is a demo Blazor application (default). I created 2 custom application profiles: Development and Production. Both should be debuggable just with pressing F5 key in Visual Studio.
Then I created a dummy Razor Component Library and named it RCL.
I made it a dependency for the main project.
Inside my dummy RCL, within wwwroot
directory I added extra.css
file.
The role of that file is to change the background color to light green.
If it happens - it means the file has been loaded. If the background remains gray / white, it is not loaded.
Here's the _Host.cshtml
fragment loading the CSS:
<link href="_content/RCL/extra.css" rel="stylesheet" />
Try to run it. It works. However on one condition:
ASPNETCORE_ENVIRONMENT
environment variable MUST be set to "Development".
If you test the Production
profile (or change the environment variable to "Production") and then run the application - the extra.css
file will not be loaded.
The background doesn't change to green, so something is wrong. Why does it happen? Is it a bug in Visual Studio?
If you wonder why do I need to set this environment variable: it allows loading of additional
appsettings.[ASPNETCORE_ENVIRONMENT].json
file. So I can have different configurations for my app. I need to test my app with different configurations. Now I can only debug it in Visual Studio with "Development" configuration. When I change configuration to anything else I can't run my app because it can't load necessary JavaScript files required by components from the library.
So, expected behavior: no matter what I put into "ASPNETCORE_ENVIRONMENT" - the files from RCL should always load. Why shouldn't they?
Actual behavior: using different configurations (profiles) breaks Razor Component Library loading.