【问题标题】:How to put app.config under app.config?如何将 app.config 放在 app.config 下?
【发布时间】:2018-05-08 15:25:25
【问题描述】:

我正在尝试为不同的构建配置文件创建多个 app.config,例如 app.debug.config 和 app.release.config。如何在解决方案资源管理器中将它们放在一起?

【问题讨论】:

    标签: visual-studio msbuild app-config


    【解决方案1】:

    通过右键单击应用程序。配置并单击添加配置转换。 如果找不到添加配置转换,则应从管理扩展中下载配置转换。

    【讨论】:

      【解决方案2】:

      视觉表示基于 csproj 文件中的 DependentUpon 元数据。

      例如,当您有 3 个配置文件时,您可以这样设置元数据:

      <None Include="App.config" />
      <None Include="App.Debug.config" DependentUpon="App.config" />
      <None Include="App.Debug.BackupDb.config" DependentUpon="App.Debug.config" />
      

      这导致解决方案资源管理器中的以下表示:

      对于旧版本(VS 2017 之前),您需要将 DependentUpon 元数据添加为 None 元素下方的元素,而不是将其添加为属性。

      为了与 VS 2015 及更低版本兼容,该项目的 xml 将是:

      <None Include="App.Debug.config">
        <DependentUpon>App.config</DependentUpon>
      </None>
      

      【讨论】:

      • 没有 VS GUI 可以做到这一点吗?
      • 我不知道。一些项目系统内置了这个逻辑 - 例如appsettings.*.json 的 asp.net 核心项目,我认为即使是 Web 项目也可能在打开时更新元数据(目前不确定)
      • 当在None 下添加为element 时,应使用哪个attribute 指定文件名?
      • @mikael-dúi-bolinder 在none下作为子元素添加时,不要使用属性,直接放&lt;DependentUpon&gt;App.config&lt;/DependentUpon&gt;
      猜你喜欢
      • 2016-01-19
      • 1970-01-01
      • 2010-09-30
      • 2011-05-18
      • 1970-01-01
      • 2021-05-31
      • 2017-03-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多