水可载舟,亦可覆舟|

Z_DK

园龄:3年7个月粉丝:2关注:11

.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  阅读(104)  评论(0编辑  收藏  举报
点击右上角即可分享
微信分享提示
评论
收藏
关注
推荐
深色
回顶
收起