MSBuild 因 /p:OutDir 参数而失败

MSBuild fails with /p:OutDir parameter

在 VS2015 中,我创建了一个测试 C++ 控制台应用程序 'Kon'(新建项目->Visual C++->Win32->Win32 控制台应用程序)。

如果我使用 /p:OutDir 参数启动 MSBuild,它总是失败:

*C:\examples\Kon>msbuild /p:Configuration="Release" /p:OutDir="C:\out\"

Microsoft (R) 构建引擎版本 14.0.25420.1 版权所有 (C) Microsoft Corporation。版权所有。 一次构建此解决方案中的项目。要启用并行构建,请添加“/m”开关。 构建于 2018 年 5 月 8 日 4:29:00 下午开始。 节点 1 上的项目 "C:\examples\Kon\Kon.sln"(默认目标)。 验证解决方案配置: 构建解决方案配置 "Release|x64"。 项目 "C:\examples\Kon\Kon.sln" (1) 正在节点 1(默认目标)上构建 "C:\examples\Kon\Kon\Kon.vcxproj" (2)。 C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppCommon.targets(31,5): error MSB4184: 表达式“[System.IO.Path]::Combine(C:\examples\Kon\Kon\, C:\out"\Kon.exe)" c 无法评估。路径中的非法字符。 [C:\examples\Kon\Kon\Kon.vcxproj] 完成构建项目 "C:\examples\Kon\Kon\Kon.vcxproj"(默认目标)——失败。 完成构建项目 "C:\examples\Kon\Kon.sln"(默认目标)——失败。 构建失败。 "C:\examples\Kon\Kon.sln"(默认目标)(1) -> "C:\examples\Kon\Kon\Kon.vcxproj"(默认目标)(2) -> C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppCommon.targets(31,5):错误 MSB4184:表达式“[System.IO.Path] ::Combine(C:\examples\Kon\Kon\, C:\out"\Kon.exe)" 无法评价。路径中的非法字符。 [C:\examples\Kon\Kon\Kon.vcxproj] 0 条警告 1 个错误 已用时间 00:00:00.12*

我在各种 C++ 项目(包括 MFC 和 ATL)中遇到同样的错误,但 C# 项目使用此选项构建良好。

如果你看

error MSB4184: The expression "[System.IO.Path]::Combine(C:\examples\Kon\Kon\, C:\out"\Kon.exe)" cannot be evaluated. Illegal characters in path.

路径中间有双引号。因此,如果您像这样从 OutDir 参数中删除双引号 /p:OutDir=C:\out 那么它应该会按预期工作。