.Net7 自动拷贝appsettings.json到debug文件下
- IDE
Rider
在配置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文件到运行目录方便很多