5

I have a really simple build script that looks like this:

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

The problem is the Bundle target, only the %(BuildArtifacts.FullPath) gets extracted, %(BuildArtifacts.FullPath) is ignored when the scripts executes.

The command looks like this when executing:

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

As you can see, the destination path is not there, if I hard code the paths or just the destination path it all works. Any suggestion on what I am doing wrong here?

Update I managed to solve the problem, I removed the last part WorkingDirectory="C:\Windows\" And changed the script into this:

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

and now it's working :)

Pelle
  • 2,755
  • 7
  • 42
  • 49
  • 1
    Use built-in `` task instead of `xcopy` invocation: http://msdn.microsoft.com/en-us/library/3e54c37h.aspx – skolima May 09 '12 at 11:11

2 Answers2

3

I managed to solve this. I've updated the question with the solution.

I removed the last part WorkingDirectory="C:\Windows\" And changed the script into this:

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

and now it's working :)

hrh
  • 658
  • 1
  • 14
  • 24
Pelle
  • 2,755
  • 7
  • 42
  • 49
0

You need to execute xcopy twice. You are trying to use task batching for two different item arrays in the same invocation, it doesn't work like that. Try this:

<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>
Brian Kretzler
  • 9,748
  • 1
  • 31
  • 28
  • Hmm, I could not get that to work, xcopy needs a destination path, and that is what %(Application.FullPath) was supposed to be. I'm not sure I fully understand the MSBuild syntax – Pelle May 10 '12 at 20:38