Blazor WASM. ASP.NET Hosted appsettings.json

454 Views Asked by At

When running my project from the server side of the project in visual studio I am unable to access appsettings.{env}.json. All keys in the specific env json file return null on the builder.Configuration object. They only load in the main appsettings.json file. The environment for debugging is the same in the project.server and project.client (Pretty sure the client env shouldn't matter) for the particular json file. Haven't seen anybody else with this problem, what am I missing? Thanks

[EDIT]
.NET 6.0
Below is set in both Project.Server and Project.Client Debug launch profiles
ASPNETCORE_ENVIRONMENT=Development

Program.cs in Project.Server

IConfiguration config = builder.Configuration;
var serverVersion = new MySqlServerVersion(new Version(10, 7));
builder.Services.AddDbContext<ProjectMariaDbContext>(
dbContextOptions => dbContextOptions
                    .UseMySql(config["ConnectionStrings:MariaDb"], serverVersion) );

appsettings.Development.json in Project.Server

{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft.AspNetCore": "Warning"
    },
    "ConnectionStrings": {
      "MariaDb": "server=maria; port=3306; database=project; user=root; password=testing;"
    }
  }
}

Testing in the immediate Immediate window at a break point on adding dbcontext line

config["ConnectionStrings:MariaDb"]
null

Also to note I am running the project from the Project.Server configuration in VS

0

There are 0 best solutions below