如何修复 Visual Studio 2010 中的错误 MSB4018?

How do I fix Error MSB4018 in Visual Studio 2010?

error MSB4018: The"VCMessage" task failed unexpectedly.
System.FormatException: Index (zero based) must be greater than or equal to zero and less than the size of the argument list.
at System.Text.StringBuilder.AppendFormat(IFormatProvider provider, String format, Object[] args)
at System.String.Format(IFormatProvider provider, String format, Object[] args)
at Microsoft.Build.Shared.ResourceUtilities.FormatString(String unformatted, Object[] args)
at Microsoft.Build.Utilities.TaskLoggingHelper.FormatString(String unformatted, Object[] args)
at Microsoft.Build.Utilities.TaskLoggingHelper.FormatResourceString(String resourceName, Object[] args)
at Microsoft.Build.Utilities.TaskLoggingHelper.LogWarningWithCodeFromResources(String messageResourceName, Object[] messageArgs)
at Microsoft.Build.CPPTasks.VCMessage.Execute()
at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask, Boolean& taskResult) C:\\Program Files (x86)\\MSBuild\\Microsoft.Cpp\\v4.0\\Microsoft.CppBuild.targets 990 6 vtk_minimal


我遇到了同样的问题。我有一个旧的 Visual Studio 2005 C 项目,我用 Visual Studio 2010 C 重新打开了它。对我来说,Microsoft Connect 提出的第一个建议奏效了:

The issue stems from the unexpected $(TargetDir) found in the property page under Link->OutputFile. During the build process, we tried to expand the OutputFile to a fullpath but only got an empty value. Thus, it led to the index out-of-bound exception.

It is unlikely we will be able to fix these before VS2010 release. The workaround is to correct OutputPath or inherit from parent.

右键单击项目并转到属性 > 链接器 > 常规。然后将 "Output File" 设置为 ""

希望也能为你解决这个问题。


我不知道出了什么问题。为我解决此错误的唯一方法是删除配置并创建一个新配置。
因此,在 Configuration Manager 中,我删除了不会构建的那个,并从一个类似的中重新创建它。