使用MsBuild进行xcopy

时间:2012-05-09 11:07:46

标签: msbuild xcopy msbuild-4.0

我有一个非常简单的构建脚本,如下所示:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0" DefaultTargets="Bundle">

<ItemGroup>
    <BuildArtifacts Include="..\_buildartifacts" />
    <Application    Include="..\_application" />
</ItemGroup>

<Target Name="Clean">
    <RemoveDir Directories="@(BuildArtifacts)" />
    <RemoveDir Directories="@(Application)" />
</Target>

<Target Name="Init" DependsOnTargets="Clean">
    <MakeDir Directories="@(BuildArtifacts)" />
    <MakeDir Directories="@(Application)" />
</Target>

<Target Name="Bundle" DependsOnTargets="Compile">
    <Exec Command="xcopy.exe %(BuildArtifacts.FullPath) %(Application.FullPath) /e /EXCLUDE:$(MSBuildProjectDirectory)\files_to_ignore_when_bundling.txt" WorkingDirectory="C:\Windows\" />
</Target>

问题是Bundle目标,只有%(BuildArtifacts.FullPath)被解压缩,脚本执行时会忽略%(BuildArtifacts.FullPath)

执行时命令如下所示:

xcopy.exe C:\@Code\blaj_buildartifacts /e /EXCLUDE:C:\@Code\blaj\files_to_ignore_when_bundling.txt" exited with code 4

正如您所看到的,目标路径不在那里,如果我硬编码路径或只是目标路径它都工作。我在这里做错了什么建议?

更新 我设法解决了问题,我删除了最后一部分WorkingDirectory="C:\Windows\" 并将脚本更改为:

<Exec Command="xcopy.exe @(BuildArtifacts) @(Application) /e /EXCLUDE:$(MSBuildProjectDirectory)\files_to_ignore_when_bundling.txt" />

现在它正在运作:)

2 个答案:

答案 0 :(得分:2)

我设法解决了这个问题。我已经用解决方案更新了问题。

我删除了最后一部分WorkingDirectory =“C:\ Windows \”并将脚本更改为:

 <Exec Command="xcopy.exe @(BuildArtifacts) @(Application) /e /EXCLUDE:$(MSBuildProjectDirectory)\files_to_ignore_when_bundling.txt" />

现在它正在运作:)

答案 1 :(得分:0)

您需要执行两次xcopy。您正在尝试在同一个调用中对两个不同的项目数组使用任务批处理,它不会像那样工作。试试这个:

<Target Name="Bundle" DependsOnTargets="Compile">
  <Exec Command="xcopy.exe %(BuildArtifacts.FullPath) /e /EXCLUDE:$(MSBuildProjectDirectory)\files_to_ignore_when_bundling.txt" WorkingDirectory="C:\Windows\" />
  <Exec Command="xcopy.exe %(Application.FullPath) /e /EXCLUDE:$(MSBuildProjectDirectory)\files_to_ignore_when_bundling.txt" WorkingDirectory="C:\Windows\" />
</Target>