【问题标题】:Choose launchSettings.json profile based on build configuration根据构建配置选择 launchSettings.json 配置文件
【发布时间】:2020-09-04 02:22:24
【问题描述】:

我需要根据选择的构建配置从 launchSettings.json 中选择配置文件。假设我已经构建了 Debug、Debug-2 配置,我需要从 launchSettings.json 为它们中的每一个选择不同的配置文件。有没有办法做到这一点?

【问题讨论】:

  • 是否有您不能使用启动配置文件选择器下拉菜单作为运行按钮的原因?
  • 是的,有。因此,我们使用远程调试,当您选择构建配置时,每个配置都有一个远程调试机器,并且有一个预构建步骤进行一些复制并需要远程调试机器名称。这只是多一步,你需要记住去做,所以它不是很实用。

标签: c# visual-studio asp.net-core visual-studio-2019 csproj


【解决方案1】:

在构建过程中,我使用“复制”MSBuild 任务用 Debug 或 Release 版本覆盖 launchSettings.json:

  <ItemGroup>
    <UpToDateCheckInput Include="Properties/launchSettings.$(Configuration).json" />
  </ItemGroup>

  <Target Name="CleanLaunchSettings" AfterTargets="Clean">
    <Message Importance="high" Text="Deleting launchSettings.json..." />
    <Delete Files="Properties/launchSettings.json" />
  </Target>

  <Target Name="CopyLaunchSettings" AfterTargets="Build" Inputs="Properties/launchSettings.$(Configuration).json" Outputs="Properties/launchSettings.json">
    <Message Importance="high" Text="Copying launchSettings.$(Configuration).json..." />
    <Copy SourceFiles="Properties/launchSettings.$(Configuration).json" DestinationFiles="Properties/launchSettings.json" />
  </Target>

【讨论】:

    猜你喜欢
    • 2017-06-13
    • 1970-01-01
    • 2013-07-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-05
    • 1970-01-01
    相关资源
    最近更新 更多