【问题标题】:How to avoid Visual Studio 2022 to add project configuration to output path如何避免 Visual Studio 2022 将项目配置添加到输出路径
【发布时间】:2022-08-22 05:30:17
【问题描述】:

Visual Studio 2022 正在向基本输出路径添加子文件夹。

有没有办法阻止它在输出路径中添加 Release/Debug 子文件夹?

Visual Studio 2022 - Project properties

  • 这些文件夹用于区分构建的发布和调试配置。无论如何,如果您打算只对项目进行一次配置构建,您可以尝试here 中显示的内容。只需替换输出路径中的 [build]/[debug] 子文件夹。
  • 感谢@Mubin 的评论。该文档与我的 Visual Studio 项目的配置不匹配。在 Build>Output>Base output path 中,我设置了没有 build/release 子文件夹的目录。该文件夹稍后会根据配置添加。
  • 请编辑问题以将其限制为具有足够详细信息的特定问题,以确定适当的答案。

标签: visual-studio-2022


【解决方案1】:

输出路径是一堆 MSBuild 属性的串联。根据您的项目类型,它可能发生在项目文件、显式导入的目标文件或隐式导入(例如通过 MSBuild SDK)中。在任何这些情况下,您都应该能够通过在项目文件中显式设置值来覆盖它。

以第 3 种情况为例(使用 Microsoft.NET.Sdk),在 Microsoft.NET.DefaultOutputPaths.targets 中,您将找到如下指定的默认值:

    <BaseOutputPath Condition="'$(BaseOutputPath)' == ''">bin\</BaseOutputPath>
    <BaseOutputPath Condition="!HasTrailingSlash('$(BaseOutputPath)')">$(BaseOutputPath)\</BaseOutputPath>
    <OutputPath Condition="'$(OutputPath)' == '' and '$(PlatformName)' == 'AnyCPU'">$(BaseOutputPath)$(Configuration)\</OutputPath>
    <OutputPath Condition="'$(OutputPath)' == '' and '$(PlatformName)' != 'AnyCPU'">$(BaseOutputPath)$(PlatformName)\$(Configuration)\</OutputPath>
    <OutputPath Condition="!HasTrailingSlash('$(OutputPath)')">$(OutputPath)\</OutputPath>

请注意$(OutputPath) 基本上是如何将$(Configuration) 附加到$(BaseOutputPath) 的。

如果您希望始终拥有相同的输出路径,您可以在项目文件中设置&lt;OutputPath&gt;Your\Desired\Path&lt;/OutputPath&gt;。设置值后,将根据 now-false 条件跳过上面的默认逻辑('$(OutputPath)' 不再为空)。

但是,这可能会破坏增量构建如果您构建不同的配置而不删除构建之间的输出文件夹的内容。

【讨论】:

    【解决方案2】:

    我知道这是一个老问题,但这是基于Microsoft's Debugger Settings 的完整解决方案:

    • 列表项 单击项目> [项目名称] 在 Build > Output 中,将 Base output path 更改为 C:[full directory path][name of project] 单击项目 > 编辑项目文件 添加 错误的 错误的
      C:[完整目录路径][项目名称]

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-11-13
      • 1970-01-01
      • 2021-12-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-19
      相关资源
      最近更新 更多