在发布模式下构建时,有没有办法自动使用单独的app.config?
换句话说,我想用一个app.config测试,然后用另一个发布。
目前,我保留了一个单独的副本,名为app.config.production,并在构建发布后手动覆盖bin\Release\Application.exe.config。
发布于 2021-07-09 00:08:34
一个干净的解决方案是将2个文件App.Debug.config和App.Release.config分组到App.config中,并根据编译时的配置将好的文件更改为App.config:
<ItemGroup>
<None Include="App.config" />
<None Include="App.Debug.config">
<DependentUpon>App.config</DependentUpon>
</None>
<None Include="App.Release.config">
<DependentUpon>App.config</DependentUpon>
</None>
</ItemGroup>
<Target Name="SetAppConfig" BeforeTargets="Compile">
<Copy SourceFiles="App.Debug.config" DestinationFiles="App.config" OverwriteReadOnlyFiles="true" Condition=" '$(Configuration)' == 'Debug' " />
<Copy SourceFiles="App.Release.config" DestinationFiles="App.config" OverwriteReadOnlyFiles="true" Condition=" '$(Configuration)' == 'Release' " />
</Target>使用此解决方案,您将在Visual Studio中获得类似以下内容:

https://stackoverflow.com/questions/1295497
复制相似问题