MSB4018: Tugas gagal secara tak terduga
Kesalahan ini dipancarkan ketika tugas gagal dengan pengecualian yang tidak tertangani. Ini umumnya merupakan tanda bug dalam tugas.
Kesalahan MSB4018 dapat disebabkan saat menjalankan tugas di lingkungan yang tidak disiapkan, misalnya ketika tugas memiliki dependensi x86 tetapi berjalan di lingkungan MSBuild 64-bit. Ini dapat bermanifestasi sebagai 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()
Untuk mengatasinya, pastikan bahwa tugas mengekspresikan dependensi pada lingkungan runtime yang diperlukan dalam elemen UsingTask milik tugas.