如何修复错误MSB4018:Visual Studio 2013中的"VCMessage"任务意外失败

Ger*_*elt 10 msvc12

这就是我所看到的:

1>------ Build started: Project: xxx (xxx\xxx), Configuration: Debug Win32 ------
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.Cpp.Platform.targets(64,5): error MSB4018: The "VCMessage" task failed unexpectedly.
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.Cpp.Platform.targets(64,5): error MSB4018: System.FormatException: Index (zero based) must be greater than or equal to zero and less than the size of the argument list.
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.Cpp.Platform.targets(64,5): error MSB4018:    at System.Text.StringBuilder.AppendFormat(IFormatProvider provider, String format, Object[] args)
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.Cpp.Platform.targets(64,5): error MSB4018:    at System.String.Format(IFormatProvider provider, String format, Object[] args)
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.Cpp.Platform.targets(64,5): error MSB4018:    at Microsoft.Build.Shared.ResourceUtilities.FormatString(String unformatted, Object[] args)
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.Cpp.Platform.targets(64,5): error MSB4018:    at Microsoft.Build.Utilities.TaskLoggingHelper.FormatString(String unformatted, Object[] args)
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.Cpp.Platform.targets(64,5): error MSB4018:    at Microsoft.Build.Utilities.TaskLoggingHelper.FormatResourceString(String resourceName, Object[] args)
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.Cpp.Platform.targets(64,5): error MSB4018:    at Microsoft.Build.Utilities.TaskLoggingHelper.LogErrorWithCodeFromResources(String messageResourceName, Object[] messageArgs)
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.Cpp.Platform.targets(64,5): error MSB4018:    at Microsoft.Build.CPPTasks.VCMessage.Execute()
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.Cpp.Platform.targets(64,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.Cpp.Platform.targets(64,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__20.MoveNext()
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Run Code Online (Sandbox Code Playgroud)

并且google和SO搜索中列出的解决方案无法提供(删除尾部斜杠,还原为默认值$(OutDir)$(TargetDir)路径等)


上下文

这涉及从MSVC2012迁移的几个项目.从同一个MSVC2012环境迁移的具有相同项目/解决方案布局的其他项目没有眨眼,而有些则表现出此错误,这会阻止任何类型的成功编译/构建结果.

Ger*_*elt 17

修复

该错误是由于项目配置字段Platform Toolset.(.vcproj项目文件应列出如此处的值v120)

之前:

<PlatformToolset>
</PlatformToolset>
Run Code Online (Sandbox Code Playgroud)

之后:

<PlatformToolset>v120</PlatformToolset>
Run Code Online (Sandbox Code Playgroud)

可以通过项目"属性"面板>"配置属性">"常规">"平台工具集"在DevStudio中设置此值::从下拉列表中选择一个值.


发现的方式:

  • 在相同类型的MSVC2013中创建一个空的项目

  • 使用Beyond Compare(或其他可视化差异工具,可以轻松编辑通过复制块进行比较的文件)来复制设置的文件并进行测试(通过重新加载到DevStudio并build在那里运行进程).

  • 下一个副本跨项目设置的位(如果您的原始项目有多个构建目标,如我的(Win32/x64/Itanium)),则复制块,再次测试.

  • 冲洗并重复上述步骤,直到您的"新"项目出现与旧项目相同的问题.缩小到.vcproj文件中的最小XML子集.


在此之前尝试过的相关SO问题和博客:

结论:如果遇到此问题,请检查所有项目配置条目.当推动推进时,通过上面的比较和测试分而治之的过程挖掘出错误.