Search code examples
msbuildcopymsbuild-task

Why does MSBuild copy task not copy?


I am trying to copy binaries created by my build to a certain folder using the MSBuild Copy task. Unfortuately, the process fails silently. No error message is issued and no files are copied.

Here is the relevant part of my .csproj file:

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

As you can see I have already added messages for debug purposes. I call msbuild using the following command line:

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

Here is the relevant excerpt from my build log:

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)

As you can see, the files to copy have been identified correctly while the copied files are empty. How can I find out why the copy process fails?


Solution

  • You're not referencing the MySourceFiles item in the copy task, but the MySourceFiles property.

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

    Should be

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