添加 /p:Platform="Any CPU" 参数强制在调试配置中构建

Ang*_*ker 5 c# msbuild roslyn windows-10 visual-studio-2017

我运行以下命令来构建我的解决方案(C# 中的所有项目):

MSBuild.exe foo.sln /t:Build /p:Configuration=Release /p:Platform="Any CPU"
Run Code Online (Sandbox Code Playgroud)

它在调试配置中构建它。如果我删除对“任何 CPU”的引用

MSBuild.exe foo.sln /t:Build /p:Configuration=Release
Run Code Online (Sandbox Code Playgroud)

构建是在发布配置中构建的。

这是为什么?我在这里错过了一些简单的东西吗?

Leo*_*SFT 5

添加 /p:Platform="Any CPU" 参数强制在调试配置中构建

该项目的输出目录相关的属性OutputPathPropertyGroup项目中的文件foo.csproj

根据您的描述,您OutputPath的项目文件中可能没有正确配置目标平台,例如:

  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    <PlatformTarget>AnyCPU</PlatformTarget>
    <DebugType>pdbonly</DebugType>
    <Optimize>true</Optimize>
    <OutputPath>bin\Debug\</OutputPath>
    <DefineConstants>TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
Run Code Online (Sandbox Code Playgroud)

如果我们<OutputPath>bin\Debug\</OutputPath>为 Release 配置,那么我们将在 Debug 文件夹中获得输出。

因此,要解决此问题,您需要检查OutputPath项目文件中的属性,确保它与目标平台匹配。

希望这可以帮助。


Ang*_*ker 1

回答我自己的问题。当我试图找到我的解决方案中存在问题的复杂内容时(例如,梳理十几个 .csproj 文件),问题却简单得令人尴尬。

在解决方案/配置管理器中,对于 Release/AnyCPU 设置,某些项目被标记为“调试”(不知道为什么 - 该解决方案可能已有十年历史)。将它们设置为 Release 解决了问题。