【问题标题】:Changing appsetings.json location in .net6更改 .net6 中的 appsettings.json 位置
【发布时间】:2022-07-02 22:38:36
【问题描述】:

我现在有 1 个项目的解决方案。我在 .net core 6 中做一个 webApi。我现在需要在同一个解决方案中创建一个附加项目,其中放置了一些共享的东西,一旦添加了更多的项目就会使用这些东西。

大部分情况下我没有问题,但移动 appsetings.json 文件有点棘手。

据我了解,在我的主项目中,这两行代码加载了 appsettings 文件:

var builder = WebApplication.CreateBuilder(args);

ConfigurationManager configuration = builder.Configuration;

但是,一旦我将 appsetings.json 文件移动到另一个项目中,第一个项目将无法再访问它。有人可以帮我解决这个问题吗?

【问题讨论】:

    标签: asp.net .net-6.0 appsettings


    【解决方案1】:
    var diretorio = Directory.GetCurrentDirectory() + "\\App_Config\\";
    builder.Host.ConfigureAppConfiguration((hostingContext, config) =>
    {
        config.AddJsonFile(diretorio + "appsettings.json",
                           optional: true,
                           reloadOnChange: true);
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-08-20
      • 2022-11-04
      • 1970-01-01
      • 2016-11-06
      • 2016-01-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多