首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Visual Studio:区分调试模式和发布模式的app.config

Visual Studio:区分调试模式和发布模式的app.config
EN

Stack Overflow用户
提问于 2009-08-18 17:54:08
回答 7查看 52.9K关注 0票数 51

在发布模式下构建时,有没有办法自动使用单独的app.config?

换句话说,我想用一个app.config测试,然后用另一个发布。

目前,我保留了一个单独的副本,名为app.config.production,并在构建发布后手动覆盖bin\Release\Application.exe.config。

EN

Stack Overflow用户

发布于 2021-07-09 00:08:34

一个干净的解决方案是将2个文件App.Debug.configApp.Release.config分组到App.config中,并根据编译时的配置将好的文件更改为App.config

代码语言:javascript
复制
<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中获得类似以下内容:

票数 1
EN
查看全部 7 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/1295497

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档