MSBUILD:包含额外文件的构建包
本文关键字:构建 文件 包含额 MSBUILD | 更新日期: 2023-09-27 18:15:16
在过去的一周里,我一直在尝试实现位于:http://blog.samstephens.co.nz/2010-10-18/msbuild-including-extra-files-multiple-builds/的解决方案。
它是基于赛义德的实现:http://sedodream.com/CommentView,guid,803d77d7-a220-4cee-a803-f6291cd4ba71.aspx(它工作完美),但是我需要来自多个位置的文件和赛义德的解决方案不考虑这种情况。
虽然理论上Sam的解决方案提供了我所需要的,但我无法构建它(尽管剪切和粘贴了他的解决方案,并且只修改了路径以反映我的环境)。这几天来,我一直对下面的错误耿耿于怀:[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
这是我对Sam的目标的实现:
<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>
我认为它可能与空格(或通配符)有关,所以我尝试了以下内容:
使用"详细"answers"诊断"日志级别检查日志
混合双引号和单引号的各种形式
注释掉"Service References"节点。(包含图片的路径没有空格)
指向具有绝对路径的单个文件。因此消除了通配符和由于路径包含空格而导致的错误。我以为这肯定会解决问题,但它失败了相同的错误上面。
在第3期之后,我完全不知所措。它不喜欢传递给它的任何
文件。任何见解将不胜感激。提前谢谢。
下面是我的目标当前的样子和相应的错误消息:
<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.
我发现你的问题了,恐怕是我的错。问题是空格在FilesForPackagingFromProject
的DestinationRelativePath
元素中是重要的。我在写这篇博文时添加了空格,使XML更容易阅读,但没有意识到这会导致代码失败。
所以如果你尝试
<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>
你的问题应该有希望得到解决。我已经更新了博客文章,删除了令人讨厌的空白。
请注意,正如Scott Stafford在他下面的评论中指出的那样,CopyAllFilesToSingleFolderForPackageDependsOn在Visual Studio 2012中已被重命名为CopyAllFilesToSingleFolderForMsdeployDependsOn。
适用于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>
这个具体的例子来自于Umbraco 4项目
我遇到了这样一个问题,其目标与Saustrup的回答中的建议相似。
在我的例子中,问题实际上是我的目标运行得太晚了,所以在构建、打包和部署应用程序之后才创建文件。这是因为我使用BeforeTargets="Build"
来运行我的目标。在回答一个更相关的问题(我只在之后找到来解决问题)时,我已经详细介绍了这一点。
MSBuild,正如您所指出的,确实存在空格问题。你有没有试过添加双斜杠:
"$(workingDir)''main''Service References''**''*"