.Net7 自动拷贝appsettings.json到debug文件下

  • IDERider 在配置json时遇到路径的问题The configuration file 'appsettings.json' was not found and is not optional. The expected physical path was
IConfiguration config = new ConfigurationBuilder()
  .AddJsonFile("appsettings.json5")
  .Build();

  • 需要修改.csproj文件 在ItemGroup下添加 添加完成如下
    <ItemGroup>
        <PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="7.0.0" />
        <PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
        <Content Include="appsettings.json5">
            <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
        </Content>
    </ItemGroup>

之后会自动拷贝appsettings.json5文件到运行目录方便很多

posted @ 2022-12-20 17:19  Z_DK  阅读(98)  评论(0编辑  收藏  举报