复制任务在MSBuild 4中不起作用

时间:2012-10-11 11:54:16

标签: .net-4.0 copy task msbuild-4.0

<Copy SourceFiles="@(sourceFiles)" DestinationFolder="$(destinationFolder)\"/>

这在MSBuild 3.5中对我来说很好用。但是因为我一直在尝试迁移到4.0,所以MSBuild会抛出这个错误。

The "Microsoft.Sdc.Tasks.Folder.Copy" task could not be loaded from the assembly Microsoft.Sdc.Tasks.dll. 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,但仍然徒劳无功。有什么想法吗?

1 个答案:

答案 0 :(得分:1)

原因很简单,

  1. 您在.NET 2.0 GAC中安装http://sdctasks.codeplex.com/。因此MSBuild 2.0或3.5可以成功加载它。
  2. .NET 4使用不同的GAC,因此MSBuild 4无法找到您在.NET 2 GAC中安装的内容。
  3. 因此,您会看到错误消息。

    我的建议,

    1. 按照http://sdctasks.codeplex.com/的建议切换到MSBuild社区包。
    2. 不应将MSBuild扩展程序集添加到GAC中,而应将其放入依赖项文件夹(例如lib)中,并将其添加到源代码管理中。
    3. 修改项目文件(例如csproj)时,请确保在<UsingTask>中使用依赖文件夹的汇编路径。
    4. 我的开源项目#SNMP使用Gendarme MSBuild扩展,我已经使用了上述技巧很长一段时间了,

      https://github.com/lextm/sharpsnmplib/blob/master/SharpSnmpLib/SharpSnmpLib.csproj