Partager via


code de diagnostic MSB4018

Cet article décrit le code d’erreur MSB4018.

Texte du message

MSB4018: The 'value' task failed unexpectedly.

Descriptif

Cette erreur est émise lorsqu’une tâche échoue avec une exception non gérée. Ce problème est généralement un signe d’un bogue dans la tâche.

Vous pouvez rencontrer cette erreur lorsque la build exécute une tâche dans un environnement pour lequel elle n’a pas été préparée. Par exemple, lorsqu’une tâche a une dépendance x86, mais que la tâche s’exécute dans un environnement MSBuild 64 bits. Ce scénario peut se manifester en tant qu’exception System.DllNotFoundException , comme illustré dans la sortie suivante :

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()

Résolution

Vérifiez que la tâche exprime une dépendance sur l’environnement d’exécution dont elle a besoin dans l’élément UsingTask de la tâche.

S’applique à

Toutes les versions de MSBuild