如何根据构建配置有条件地部署 app.config? [英] How to conditionally deploy an app.config based on build configuration?
问题描述
我有三个自定义构建配置 { Dev、Qs、Prd }.所以,我有三个应用程序配置 { Dev.config, Qs.config, Prd.config }.我知道如何编辑 .csproj 文件以根据当前的构建配置输出正确的文件.
I have three custom build configurations { Dev, Qs, Prd }. So, I have three app configs { Dev.config, Qs.config, Prd.config }. I know how to edit the .csproj file to output the correct one based on the current build configuration.
<Target Name="AfterBuild">
<Delete Files="$(TargetDir)$(TargetFileName).config" />
<Copy SourceFiles="$(ProjectDir)$(Configuration).config" DestinationFiles="$(TargetDir)$(TargetFileName).config" />
</Target>
我的问题是,我需要六个构建配置 { Dev, Qs, Prd } x { Debug, Release }.我需要支持每个环境的调试和发布设置(优化、pdb 等).但是,应用配置值在调试/发布之间不会改变.
My problem is, I need to have six build configurations { Dev, Qs, Prd } x { Debug, Release }. I need to support the debug and release settings (optimizations, pdb, etc) for each environment. However, the app config values don't change between debug/release.
如何使构建脚本尽可能通用并仅使用三个应用程序配置?我不想硬编码太多条件字符串.
How do I keep the build script as generic as possible and use only the three app configs? I don't want to hard code too many conditional strings.
推荐答案
类似的东西
<PropertyGroup Condition="'$(Configuration)'=='Dev_Debug' OR '$(Configuration)'=='Dev_Release'" >
<CfgFileName>Dev</CfgFileName>
</PropertyGroup>
<!-- similar for Qs & Prd -->
<Target ...>...$(CfgFileName).config...
这篇关于如何根据构建配置有条件地部署 app.config?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!