最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

.net - Using Nx to manage dotnet application - appsettings.json not being loaded - Stack Overflow

programmeradmin3浏览0评论

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 badges
Add a comment  | 

1 Answer 1

Reset to default 0

You 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();
发布评论

评论列表(0)

  1. 暂无评论