MSB4062: 无法从程序集加载任务

如果在执行任务之前无法加载任务程序集,则会发出此错误。

当在一个未准备好的环境中运行任务时,可能会导致错误 MSB4018,例如,当任务程序集面向 32 位 x86,但在 64 位 MSBuild 环境中运行时。

S:\BitnessInMSBuild\ShowErrors.proj(13,5): error MSB4062: The "TaskCompiledForx86" task could not be loaded from the assembly S:\BitnessInMSBuild\TaskCompiledForx86\bin\Debug\net472\TaskCompiledForx86.dll. Could not load file or assembly 'file:///S:\BitnessInMSBuild\TaskCompiledForx86\bin\Debug\net472\TaskCompiledForx86.dll' or one of its dependencies. An attempt was made to load a program with an incorrect format. Confirm that the <UsingTask> declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask.

若要解决此问题,请确保任务在任务的 UsingTask 元素中表示依赖于它所需要的运行时环境。