为什么MSBuild复制任务不能复制?

时间:2014-07-22 13:39:07

标签: msbuild copy msbuild-task

我正在尝试使用MSBuild Copy任务将我的构建创建的二进制文件复制到某个文件夹。不幸的是,这个过程无声地失败了。没有发出错误消息,也没有复制文件。

以下是我的.csproj文件的相关部分:

<Target Name="CopyFilesForModule" AfterTargets="AfterBuild">
  <CreateItem Include="bin\**\*.*" Exclude="bin\**\*.pdb;bin\**\*.xml">
    <Output TaskParameter="Include" ItemName="MySourceFiles" />
  </CreateItem>
  <Copy SourceFiles="$(MySourceFiles)" DestinationFolder="Areas\KoobooModule7\bin">
    <Output
          TaskParameter="CopiedFiles"
          ItemName="Changed" />
  </Copy>
  <Message Text="sourcefiles: @(MySourceFiles)" />
  <Message Text="changed:@(Changed)" Importance="high" />
</Target>

正如您所看到的,我已经添加了用于调试目的的消息。我使用以下命令行调用msbuild:

"c:\Program Files (x86)\MSBuild\12.0\Bin\MSBuild.exe" /t:rebuild /verbosity:d
iag KoobooModule7.csproj > buildlog.txt

以下是我的构建日志中的相关摘录:

Target "CopyFilesForModule: (TargetId:75)" in project "C:\Users\chris\Documents\Visual Studio 2013\Projects\KoobooModule7\KoobooModule7\KoobooModule7.csproj" (target "Build" depends on it):
Task "CreateItem" (TaskId:43)
  Task Parameter:Include=bin\**\*.* (TaskId:43)
  Task Parameter:
      Exclude=
          bin\**\*.pdb
          bin\**\*.xml (TaskId:43)
Done executing task "CreateItem". (TaskId:43)
Task "Copy" (TaskId:44)
  Task Parameter:DestinationFolder=Areas\KoobooModule7\bin (TaskId:44)
Done executing task "Copy". (TaskId:44)
Task "Message" (TaskId:45)
  Task Parameter:Text=sourcefiles: bin\CookComputing.XmlRpcV2.dll;bin\DiffPlex.dll;bin\dotless.Core.dll;bin\DotNetOpenAuth.AspNet.dll;bin\DotNetOpenAuth.Core.dll;bin\DotNetOpenAuth.OAuth.Consumer.dll;bin\DotNetOpenAuth.OAuth.dll;bin\DotNetOpenAuth.OpenId.dll;bin\DotNetOpenAuth.OpenId.RelyingParty.dll;bin\HtmlAgilityPack.dll;bin\Ionic.Zip.Reduced.dll;bin\Kooboo.CMS.Account.dll;bin\Kooboo.CMS.Caching.dll;bin\Kooboo.CMS.Common.dll;bin\Kooboo.CMS.Common.Runtime.Dependency.Ninject.dll;bin\Kooboo.CMS.Content.dll;bin\Kooboo.CMS.Form.dll;bin\Kooboo.CMS.Membership.dll;bin\Kooboo.CMS.Search.dll;bin\Kooboo.CMS.Sites.dll;bin\Kooboo.CMS.Sites.TemplateEngines.Razor.dll;bin\Kooboo.CMS.Web.dll;bin\Kooboo.dll;bin\KoobooModule7.dll;bin\KoobooModule7.dll.config;bin\Lucene.Net.Contrib.Highlighter.dll;bin\Lucene.Net.dll;bin\Microsoft.Web.Infrastructure.dll;bin\Mono.Math.dll;bin\Newtonsoft.Json.dll;bin\Ninject.dll;bin\NuGet.Core.dll;bin\Org.Mentalis.Security.Cryptography.dll;bin\System.Net.Http.dll;bin\System.Web.Helpers.dll;bin\System.Web.Mvc.dll;bin\System.Web.Razor.dll;bin\System.Web.WebPages.Administration.dll;bin\System.Web.WebPages.Deployment.dll;bin\System.Web.WebPages.dll;bin\System.Web.WebPages.Razor.dll (TaskId:45)
  sourcefiles: bin\CookComputing.XmlRpcV2.dll;bin\DiffPlex.dll;bin\dotless.Core.dll;bin\DotNetOpenAuth.AspNet.dll;bin\DotNetOpenAuth.Core.dll;bin\DotNetOpenAuth.OAuth.Consumer.dll;bin\DotNetOpenAuth.OAuth.dll;bin\DotNetOpenAuth.OpenId.dll;bin\DotNetOpenAuth.OpenId.RelyingParty.dll;bin\HtmlAgilityPack.dll;bin\Ionic.Zip.Reduced.dll;bin\Kooboo.CMS.Account.dll;bin\Kooboo.CMS.Caching.dll;bin\Kooboo.CMS.Common.dll;bin\Kooboo.CMS.Common.Runtime.Dependency.Ninject.dll;bin\Kooboo.CMS.Content.dll;bin\Kooboo.CMS.Form.dll;bin\Kooboo.CMS.Membership.dll;bin\Kooboo.CMS.Search.dll;bin\Kooboo.CMS.Sites.dll;bin\Kooboo.CMS.Sites.TemplateEngines.Razor.dll;bin\Kooboo.CMS.Web.dll;bin\Kooboo.dll;bin\KoobooModule7.dll;bin\KoobooModule7.dll.config;bin\Lucene.Net.Contrib.Highlighter.dll;bin\Lucene.Net.dll;bin\Microsoft.Web.Infrastructure.dll;bin\Mono.Math.dll;bin\Newtonsoft.Json.dll;bin\Ninject.dll;bin\NuGet.Core.dll;bin\Org.Mentalis.Security.Cryptography.dll;bin\System.Net.Http.dll;bin\System.Web.Helpers.dll;bin\System.Web.Mvc.dll;bin\System.Web.Razor.dll;bin\System.Web.WebPages.Administration.dll;bin\System.Web.WebPages.Deployment.dll;bin\System.Web.WebPages.dll;bin\System.Web.WebPages.Razor.dll (TaskId:45)
Done executing task "Message". (TaskId:45)
Task "Message" (TaskId:46)
  Task Parameter:Text=changed: (TaskId:46)
  Task Parameter:Importance=high (TaskId:46)
  changed: (TaskId:46)
Done executing task "Message". (TaskId:46)
Done building target "CopyFilesForModule" in project "KoobooModule7.csproj".: (TargetId:75)

如您所见,复制的文件为空时,已正确识别要复制的文件。如何找出复制过程失败的原因?

1 个答案:

答案 0 :(得分:4)

您并未在复制任务中引用MySourceFiles项,而是引用MySourceFiles属性。

<Copy SourceFiles="$(MySourceFiles)" DestinationFolder="Areas\KoobooModule7\bin">

应该是

<Copy SourceFiles="@(MySourceFiles)" DestinationFolder="Areas\KoobooModule7\bin">