I am using Nx to manage a monorepo. One of the projects in the repo is a dotnet application. I created this application using @nx-dotnet/core. When I run the application, instead of loading my specific appsettings.json, the IConfiguration object is just filled with my EnvironmentVariables. How can I make it load the project appsettings instead?
I am using Nx to manage a monorepo. One of the projects in the repo is a dotnet application. I created this application using @nx-dotnet/core. When I run the application, instead of loading my specific appsettings.json, the IConfiguration object is just filled with my EnvironmentVariables. How can I make it load the project appsettings instead?
Share Improve this question edited Mar 20 at 6:58 Qiang Fu 9,3971 gold badge6 silver badges16 bronze badges asked Mar 19 at 19:17 Ethan SchoferEthan Schofer 1,8565 gold badges28 silver badges60 bronze badges1 Answer
Reset to default 0You could add following codes to program.cs
//To prevent the configuration read from all sources include enviroment
builder.Configuration.Sources.Clear();
// Manually add only the JSON configuration files
builder.Configuration
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
.AddJsonFile($"appsettings.{builder.Environment.EnvironmentName}.json", optional: true, reloadOnChange: true);
//To add Enviromentvariables to configuration.
//.AddEnvironmentVariables();