How to fix 'error MSB4018: The "VCMessage" task failed unexpectedly' in Visual Studio 2013

14,283

Solution 1

The Fix

The error was due to the project configuration field Platform Toolset being empty. (The .vcproj project file should list a value such as v120 here)

Before:

<PlatformToolset>
</PlatformToolset>

After:

<PlatformToolset>v120</PlatformToolset>

This value can be set in DevStudio via project Properties panel > Configuration Properties > General > Platform Toolset :: pick one of the values from the dropdown there.


The way this was uncovered:

  • create an empty new project in MSVC2013 of the same type

  • use Beyond Compare (or another visual diff tool which can easily edit the files being compared by copying chunks across) to copy the files set across and test (by reloading into DevStudio and running the build process in there).

  • next copy across bits of the project settings (and duplicate the blocks if your original project has multiple build targets like mine had (Win32/x64/Itanium)), test again.

  • rinse and repeat the above until your 'new' project exhibits the same issue as the old one. Narrow down to a minimal XML subset in the .vcproj file.


Related SO questions and blogs which were tried before all this:

The conclusion: if you run into this issue, check all your project configuration entries. And when push comes to shove, dig the bugger out by the above compare-and-test divide-and-conquer process.

Solution 2

I had the same issue. My problem was I was using values to output file. what I Used was $(TaskName)$(TaskExt) instead of $(TargetName)$(TargetExt)

Correct value could be

In Properties -> Configuration -> Linker

output file = $(SolutionDir)\$(Platform)\$(Configuration)\$(TargetName)$(TargetExt)

Share:
14,283
Ger Hobbelt
Author by

Ger Hobbelt

Updated on June 18, 2022

Comments

  • Ger Hobbelt
    Ger Hobbelt about 2 years

    This is what I see:

    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 ==========
    

    and the solutions listed in the google and SO searches don't deliver (removing trailing slashes, reverting to default $(OutDir) or $(TargetDir) paths, etc.)


    Context

    This regards several projects which have been migrated from MSVC2012. Other projects with the same project/solution layout migrated from the same MSVC2012 environment didn't blink an eye, while some exhibit this error, which prevents any sort of successful compile/build result.

  • Or b
    Or b over 3 years
    The <PlatformToolset>v120</PlatformToolset> should be added for each configuration at this location: ... <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='XX" Label="Configuration"> ... <PlatformToolset>v120</PlatformToolset> ... </PropertyGroup> ...