MSB4018诊断代码

本文介绍MSB4018错误代码。

消息文本

MSB4018: The 'value' task failed unexpectedly.

DESCRIPTION

当任务失败并出现未经处理的异常时,将发出此错误。 此问题通常表明任务中存在一个程序错误。

当生成在未做好准备的环境中运行任务时,可能会遇到此错误。 例如,当任务具有 x86 依赖项时,该任务在 64 位 MSBuild 环境中运行。 这种情况可以表现为 System.DllNotFoundException 异常,如以下输出所示:

S:\BitnessInMSBuild\ShowErrors.proj(6,7): error MSB4018: The "AnyCPUTaskWithPInvoke" task failed unexpectedly.
S:\BitnessInMSBuild\ShowErrors.proj(6,7): error MSB4018: System.DllNotFoundException: Unable to load DLL 'Native32BitLibrary.dll': The specified module could not be found. (Exception from HRESULT: 0x8007007E)
S:\BitnessInMSBuild\ShowErrors.proj(6,7): error MSB4018:    at AnyCPUTaskWithPInvoke.AnyCPUTaskWithPInvoke.NativeMethod()
S:\BitnessInMSBuild\ShowErrors.proj(6,7): error MSB4018:    at AnyCPUTaskWithPInvoke.AnyCPUTaskWithPInvoke.OtherMethod() in S:\BitnessInMSBuild\AnyCPUTaskWithPInvoke\AnyCPUTaskWithPInvoke.cs:line 19
S:\BitnessInMSBuild\ShowErrors.proj(6,7): error MSB4018:    at AnyCPUTaskWithPInvoke.AnyCPUTaskWithPInvoke.Execute() in S:\BitnessInMSBuild\AnyCPUTaskWithPInvoke\AnyCPUTaskWithPInvoke.cs:line 12
S:\BitnessInMSBuild\ShowErrors.proj(6,7): error MSB4018:    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
S:\BitnessInMSBuild\ShowErrors.proj(6,7): error MSB4018:    at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext()

决议

确保任务在任务的 UsingTask 元素中表示它所需的运行时环境依赖项。

适用于

MSBuild 的所有版本