.NET6控制台 App.config (Debug, Release)不同环境生成

61 阅读1分钟

.NET6控制台 App.config (Debug, Release)不同环境生成


动机

本地和远程的数据库连接(connectionString)不一样, 发布时, 有时忘记了更改配置, 导致网站直接崩溃

由于项目只认 App.config, 而有需要两个不同的Config, 故, 放在不同文件夹

根目录用于发布, Debug目录用于调试


项目配置办法

项目 AspNetCore .NET6.0 (控制台模式网站)

<ItemGroup>
  <Content Remove="App.config" />
  <Content Remove="Debug\App.config" />
</ItemGroup>
<ItemGroup Condition=" '$(Configuration)' == 'Release'">
  <None Include="App.config" />
</ItemGroup>
<ItemGroup Condition=" '$(Configuration)' != 'Release'">
  <None Include="Debug\App.config" />
</ItemGroup>