How to place SomeSettings.json in RCL project so that it can be consumed by Configuration of consuming projects

Charles Kim 5 Reputation points
2024-11-02T10:19:31.8366667+00:00

I have a strategy to share App.razor from RCL project with Blazor hosing apps like Blazor Webassembly standalone app as a front-end app and Blazor hybrid apps as native apps.

I would like place all together into a RCL project(RCL) including appsettings.json file so put it in RCL/wwwroot/appsettings.json setting as Content and Copy.

Building RCL project moved it in /bin/.../wwwroot/appsettings.json.

I added Blazor Webassembly standalone app(Wasm project) into the solution, set up project reference to RCL, removed its own appsettings.json and all razor files, change Wasm.Program.cs as below:

builder.RootComponents.Add<RCL.App>("#app");
builder.RootComponents.Add<HeadOutlet>("head::after");

After bulding the solution, I have also checked RCL's appsettings.json is placed in Wasm/bin/../wwwroot/.

However, the problem is the file was not included in the configuraiton.

So, I tried adding this line in Wasm.Program but it wouldn't work.

builder.Configuration.AddJsonFile("_content/RCL/appsettings.json");

// or
// builder.Configuration.AddJsonFile("/appsettings.json");

tried also this in Wasm/wwwroot/index.html to see if the file is downloaded to browser cache but to fail.

<head>
<link rel="import" href="_content/RCL/appsettings.json"/>

How can I achieve my goal?

Blazor
Blazor
A free and open-source web framework that enables developers to create web apps using C# and HTML being developed by Microsoft.
1,594 questions
0 comments No comments
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.