.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文件到运行目录方便很多

本文作者:Z_DK

本文链接:https://www.cnblogs.com/xslx/p/16994711.html

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   Z_DK  阅读(105)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· Apifox不支持离线,Apipost可以!
· 零经验选手,Compose 一天开发一款小游戏!
· Trae 开发工具与使用技巧
· 历时 8 年,我冲上开源榜前 8 了!
· 通过 API 将Deepseek响应流式内容输出到前端
点击右上角即可分享
微信分享提示
评论
收藏
关注
推荐
深色
回顶
收起