MSBUILD: package assembly, including additional files

I had serious problems last week trying to implement a solution located at: http://blog.samstephens.co.nz/2010-10-18/msbuild-including-extra-files-multiple-builds/ .

It is based on the Sayed implementation: http://sedodream.com/CommentView,guid,803d77d7-a220-4cee-a803-f6291cd4ba71.aspx (which works fine), however I need files from several places, and the Sayed solution doesnโ€™t use "t takes this scenario into account.

Although theoretically the Sam solution provides what I need, I cannot build it (despite cutting and pasting its solution and only changing the paths to reflect my environment). I hit my head several times about the following error for several days:

[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& 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. [<PATH_TO>\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. [<PATH_TO>\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) [<PATH_TO>\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) [<PATH_TO>\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) [<PATH_TO>\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() [<PATH_TO>\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() [<PATH_TO>\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& taskResult) [<PATH_TO>\MYPROJ.csproj] [15:31:31]: Done Building Project "<PATH_TO>\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) -> [15:31:31]: "<PATH_TO>\MYPROJ.csproj" (Package target) (2) -> [15:31:31]: (CopyAllFilesToSingleFolderForPackage target) -> [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. [<PATH_TO>\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. [<PATH_TO>\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) [<PATH_TO>\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) [<PATH_TO>\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) [<PATH_TO>\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() [<PATH_TO>\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() [<PATH_TO>\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& taskResult) [<PATH_TO>\MYPROJ.csproj] [15:31:31]: 0 Warning(s) [15:31:31]: 1 Error(s) [15:31:31]: Time Elapsed 00:00:23.00 

Here's my implementation of Sam's goals:

 <Target Name="DefineCustomFiles"> <ItemGroup> <CustomFilesToInclude Include="$(workingDir)\main\img\**\*"> <Dir>img</Dir> </CustomFilesToInclude> <CustomFilesToInclude Include="$(workingDir)\main\Service References\**\*"> <Dir>ServiceReferences</Dir> </CustomFilesToInclude> </ItemGroup> </Target> <Target Name="CustomCollectFiles"> <Message Text="Here is a file list: %(CustomFilesToInclude.Identity)" /> <ItemGroup> <FilesForPackagingFromProject Include="@(CustomFilesToInclude)"> <DestinationRelativePath> %(CustomFilesToInclude.Dir)\%(RecursiveDir)%(Filename)%(Extension) </DestinationRelativePath> </FilesForPackagingFromProject> </ItemGroup> </Target> 

I thought this might have something to do with spaces (or wildcards), so here is what I tried:

  • Studied a journal with "detailed" and "diagnostic" logging levels

  • Various embodiments of mixing double quotes and single quotes

  • Commenting on the "Service Links" node. (Paths containing imgs do not have spaces)

  • An indication of a single file with an absolute path. Therefore, eliminating both patterns and errors due to a path containing spaces. I thought that MAKE SURE that this will solve the problem, but it is not with the same error above.

After release number 3, I have a complete loss. He does not like the files transferred to him.

Any insight would be greatly appreciated. Thanks in advance.

Here's what my target and the corresponding error message look like:

 <Target Name="DefineCustomFiles"> <ItemGroup> <CustomFilesToInclude Include="$(workingDir)\main\img\file.gif"> <Dir>img</Dir> </CustomFilesToInclude> </ItemGroup> </Target> 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. 
+8
c # msbuild
source share
4 answers

I found your problem, and I am afraid that it is my fault. The problem is that spaces are significant in the DestinationRelativePath FilesForPackagingFromProject element. I added spaces when I made a blog post to make it easier to read XML without realizing that this would cause code to crash.

So if you try

 <Target Name="CustomCollectFiles"> <Message Text="Here is a file list: %(CustomFilesToInclude.Identity)" /> <ItemGroup> <FilesForPackagingFromProject Include="@(CustomFilesToInclude)"> <DestinationRelativePath>%(CustomFilesToInclude.Dir)\%(RecursiveDir)%(Filename)%(Extension)</DestinationRelativePath> </FilesForPackagingFromProject> </ItemGroup> </Target> 

Your problems, I hope, will be fixed. I updated my blog post to remove offensive spaces.

Note that, as Scott Stafford points out in his comment below, CopyAllFilesToSingleFolderForPackageDependsOn has been renamed CopyAllFilesToSingleFolderForMsdeployDependsOn in Visual Studio 2012.

+7
source share

I ran into such a problem, with a goal similar to the suggestion in Sastrup's answer.

In my case, the problem was that my goal worked too late, so creating files after creating, packaging and deploying the application. This is because I used BeforeTargets="Build" to launch my goal. I examined this in much more detail in the answer to a more important question (which I found only after solving the problem) here .

+3
source share

This works in Visual Studio 2013 for Web:

 <Target Name="BeforeBuild"> <ItemGroup> <Content Include="bin\**" Exclude="**/.git*" /> <Content Include=".\Global.asax" /> <Content Include=".\umbraco\**" /> <Content Include=".\usercontrols\**" /> <Content Include=".\umbraco_client\**" /> <Content Include=".\App_Code\**" /> <Content Include=".\App_Plugins\**" /> <Content Include=".\App_Data\*-*-*-*-*\**" /> <Content Include=".\App_Data\packages\**" /> <Content Include=".\App_Data\access.*" /> <Content Include=".\Views\**" /> <Content Include=".\App_Browsers\**" /> <Content Include=".\uSync\**" /> <Content Include=".\media\**" /> </ItemGroup> </Target> 

This specific example is from the Umbraco 4 project.

+2
source share

MSBuild, as you pointed out, has problems with spaces. You tried to add double slashes:

 "$(workingDir)\\main\\Service References\\**\\*" 
0
source share

All Articles