title: MSBUILD: Build Package including extra files
body: <p>I've been having some serious challenges over the past week trying to implement the solution located at: <a href="http://blog.samstephens.co.nz/2010-10-18/msbuild-including-extra-files-multiple-builds/" rel="noreferrer">http://blog.samstephens.co.nz/2010-10-18/msbuild-including-extra-files-multiple-builds/</a>.  </p>
  
  <p>It's based off of Sayed's implementation: <a href="http://sedodream.com/CommentView,guid,803d77d7-a220-4cee-a803-f6291cd4ba71.aspx" rel="noreferrer">http://sedodream.com/CommentView,guid,803d77d7-a220-4cee-a803-f6291cd4ba71.aspx</a> (which works perfectly), however I need files from multiple locations and Sayed's solution doesn't account for that scenario.</p>
  
  <p>While in theory Sam's solution provides <em>exactly</em> what I need, I can't get it to build (despite cut and pasting his solution and only modifying the paths to reflect my environment).  I've been banging my head against the following error for several days:</p>
  
  <pre><code>[15:31:30]: [CopyPipelineFiles] C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.targets(1852, 5): error MSB4018: The "CopyPipelineFiles" task failed unexpectedly.  
  System.ArgumentException: Illegal characters in path.  
  at System.IO.Path.CheckInvalidPathChars(String path) at System.IO.Path.Combine(String path1, String path2)  
  at Microsoft.Web.Publishing.Tasks.CopyPipelineFiles.CopyPipelineFilesToFolder(TaskLoggingHelper log, ITaskItem[] allpipeLineItems, String sourceFolderName, String targetFolderName, ItemMetadataFilter itemMetadataSkipFilter, Boolean fUpdateItemSpec, Boolean deleteItemsMarkAsExcludeTrue, List`1 updatedPipeLineItems, List`1 failedPipeLineItems)  
  at Microsoft.Web.Publishing.Tasks.CopyPipelineFiles.Execute()  
  at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() 
  at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask, Boolean&amp; taskResult)    
  [15:31:31]: Process exited with code 1  
  [15:31:31]: MSBuild output:  
  [15:31:31]: C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.targets(1852,5): error MSB4018: The "CopyPipelineFiles" task failed unexpectedly. [&lt;PATH_TO&gt;\MYPROJ.csproj]  
  [15:31:31]: C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.targets(1852,5): error MSB4018: System.ArgumentException: Illegal characters in path. [&lt;PATH_TO&gt;\MYPROJ.csproj]  
  [15:31:31]: C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.targets(1852,5): error MSB4018: at System.IO.Path.CheckInvalidPathChars(String path) [&lt;PATH_TO&gt;\MYPROJ.csproj]  
  [15:31:31]: C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.targets(1852,5): error MSB4018: at System.IO.Path.Combine(String path1, String path2) [&lt;PATH_TO&gt;\MYPROJ.csproj]  
  [15:31:31]: C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.targets(1852,5): error MSB4018: at Microsoft.Web.Publishing.Tasks.CopyPipelineFiles.CopyPipelineFilesToFolder(TaskLoggingHelper log, ITaskItem[] allpipeLineItems, String sourceFolderName, String targetFolderName, ItemMetadataFilter itemMetadataSkipFilter, Boolean fUpdateItemSpec, Boolean deleteItemsMarkAsExcludeTrue, List`1 updatedPipeLineItems, List`1 failedPipeLineItems) [&lt;PATH_TO&gt;\MYPROJ.csproj]  
  [15:31:31]: C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.targets(1852,5): error MSB4018: at Microsoft.Web.Publishing.Tasks.CopyPipelineFiles.Execute() [&lt;PATH_TO&gt;\MYPROJ.csproj]  
  [15:31:31]: C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.targets(1852,5): error MSB4018: at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() [&lt;PATH_TO&gt;\MYPROJ.csproj]  
  [15:31:31]: C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.targets(1852,5): error MSB4018: at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask, Boolean&amp; taskResult) [&lt;PATH_TO&gt;\MYPROJ.csproj]  
  [15:31:31]: Done Building Project "&lt;PATH_TO&gt;\MYPROJ.csproj" (Package target(s)) -- FAILED.  
  [15:31:31]: Done Building Project "C:\buildAgent\work\8aa6ae640d0f858b\main\scripts\MYPROJ.csproj" (BatchCopyPackage target(s)) -- FAILED.  
  [15:31:31]: Build FAILED.  
  [15:31:31]: "C:\buildAgent\work\8aa6ae640d0f858b\main\scripts\MYPROJ.csproj" (BatchCopyPackage target) (1) -&gt;  
  [15:31:31]: "&lt;PATH_TO&gt;\MYPROJ.csproj" (Package target) (2) -&gt;  
  [15:31:31]: (CopyAllFilesToSingleFolderForPackage target) -&gt;  
  [15:31:31]: C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.targets(1852,5): error MSB4018: The "CopyPipelineFiles" task failed unexpectedly. [&lt;PATH_TO&gt;\MYPROJ.csproj]  
  [15:31:31]: C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.targets(1852,5): error MSB4018: System.ArgumentException: Illegal characters in path. [&lt;PATH_TO&gt;\MYPROJ.csproj]  
  [15:31:31]: C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.targets(1852,5): error MSB4018: at System.IO.Path.CheckInvalidPathChars(String path) [&lt;PATH_TO&gt;\MYPROJ.csproj]  
  [15:31:31]: C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.targets(1852,5): error MSB4018: at System.IO.Path.Combine(String path1, String path2) [&lt;PATH_TO&gt;\MYPROJ.csproj]  
  [15:31:31]: C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.targets(1852,5): error MSB4018: at Microsoft.Web.Publishing.Tasks.CopyPipelineFiles.CopyPipelineFilesToFolder(TaskLoggingHelper log, ITaskItem[] allpipeLineItems, String sourceFolderName, String targetFolderName, ItemMetadataFilter itemMetadataSkipFilter, Boolean fUpdateItemSpec, Boolean deleteItemsMarkAsExcludeTrue, List`1 updatedPipeLineItems, List`1 failedPipeLineItems) [&lt;PATH_TO&gt;\MYPROJ.csproj]  
  [15:31:31]: C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.targets(1852,5): error MSB4018: at Microsoft.Web.Publishing.Tasks.CopyPipelineFiles.Execute() [&lt;PATH_TO&gt;\MYPROJ.csproj]  
  [15:31:31]: C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.targets(1852,5): error MSB4018: at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() [&lt;PATH_TO&gt;\MYPROJ.csproj]  
  [15:31:31]: C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.targets(1852,5): error MSB4018: at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask, Boolean&amp; taskResult) [&lt;PATH_TO&gt;\MYPROJ.csproj]  
  [15:31:31]: 0 Warning(s)  
  [15:31:31]: 1 Error(s)  
  [15:31:31]: Time Elapsed 00:00:23.00  
  </code></pre>
  
  <p>Here's my implementation of Sam's targets:</p>
  
  <pre><code>&lt;Target Name="DefineCustomFiles"&gt;
      &lt;ItemGroup&gt;
        &lt;CustomFilesToInclude Include="$(workingDir)\main\img\**\*"&gt;
          &lt;Dir&gt;img&lt;/Dir&gt;
        &lt;/CustomFilesToInclude&gt;
        &lt;CustomFilesToInclude Include="$(workingDir)\main\Service References\**\*"&gt;
          &lt;Dir&gt;ServiceReferences&lt;/Dir&gt;
        &lt;/CustomFilesToInclude&gt;
      &lt;/ItemGroup&gt;
  &lt;/Target&gt;
  
  &lt;Target Name="CustomCollectFiles"&gt;
    &lt;Message Text="Here is a file list: %(CustomFilesToInclude.Identity)" /&gt;
      &lt;ItemGroup&gt;
        &lt;FilesForPackagingFromProject Include="@(CustomFilesToInclude)"&gt;
          &lt;DestinationRelativePath&gt;
            %(CustomFilesToInclude.Dir)\%(RecursiveDir)%(Filename)%(Extension)
          &lt;/DestinationRelativePath&gt;
        &lt;/FilesForPackagingFromProject&gt;
      &lt;/ItemGroup&gt;
  &lt;/Target&gt;
  </code></pre>
  
  <p>I thought it may have something to do with spaces (or the wildcard symbols) so here's what I've tried:</p>
  
  <ul>
  <li><p>Examined the log with both "detailed" and "diagnostic" logging levels</p></li>
  <li><p>Various incarnations of mixing double quotes and single quotes</p></li>
  <li><p>Commenting out the "Service References" node.  (The paths containing imgs have no spaces)</p></li>
  <li><p>Pointing to a single file with an absolute path. Therefore eliminating both wildcards and errors due to the path containing spaces.  I thought FOR SURE this would resolve the issue, but it failed with the same error above.</p></li>
  </ul>
  
  <p>After issue #3 I'm at a complete loss.  It doesn't like <em>any</em> files passed to it. </p>
  
  <p>Any insight would be GREATLY appreciated.  Thanks in advance.</p>
  
  <p>Here is how my target currently looks and the respective error message:</p>
  
  <pre><code>&lt;Target Name="DefineCustomFiles"&gt;
      &lt;ItemGroup&gt;
        &lt;CustomFilesToInclude Include="$(workingDir)\main\img\file.gif"&gt;
          &lt;Dir&gt;img&lt;/Dir&gt;
        &lt;/CustomFilesToInclude&gt;
      &lt;/ItemGroup&gt;
  &lt;/Target&gt;
  
  C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.targets(1852, 5): error MSB4018: The "CopyPipelineFiles" task failed unexpectedly.  
  System.ArgumentException: Illegal characters in path.
  </code></pre>