3
votes

In the msbuild script below, the first time I run the csproject the following targets get executed in sequence:

1) UnzipDLL
2) DeleteExtraneousDirs

If I was to run the csproject for the second time, the following targets get executed in sequence:

1) UnzipDLL
2) CopyFiles
3) DeleteExtraneousDirs

I'm not sure why the "CopyFiles" target doesn't run the first time. I also tried specifying the target orders by adding "BeforeTargets", "AfterTargets", and/or "DependsOnTargets", but that didn't run the CopyFiles target after the UnzipDLL target.

Also, if I specify the DefaultTargets as only "UnzipDLL" and "CopyFiles", only the "UnzipDLL" task runs the first time I run the csproject project and both tasks "UnzipDLL" and "CopyFiles" run the second time the csporjects gets executed.

Below is the msbuild script. Thanks for the help!

<Project ToolsVersion="14.0" DefaultTargets="UnzipDLL;CopyFiles;DeleteExtraneousDirs" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> 
  <PropertyGroup>
    <ReleasePath>..\..\..\..\..\TDS</ReleasePath>
    <RelDirectory>$(ReleasePath)\exe\dll\_rels</RelDirectory>
    <LibDirectory>$(ReleasePath)\exe\dll\lib</LibDirectory>
  </PropertyGroup>
  <ItemGroup>
    <LibFiles Include="$(ReleasePath)\exe\dll\lib\**\*.*;$(ReleasePath)\exe\dll\lib\*.*" />
  </ItemGroup>
  <Target Name="UnzipDLL"> 
     <Unzip ZipFileName="$(ReleasePath)\exe\utils\TDS.Packages.1.0.0.nupkg" 
        TargetDirectory="$(ReleasePath)\exe\dll\" /> 
  </Target>
  <Target Name="CopyFiles">
     <Copy SourceFiles="@(LibFiles)" DestinationFolder="$(ReleasePath)\exe\dll\%(RecursiveDir)" />
  </Target>
  <Target Name="DeleteExtraneousDirs">
     <Delete Files="@(LibFiles)" />
     <RemoveDir Directories="$(RelDirectory);$(LibDirectory)" />
  </Target>
</Project>

UPDATE
To SergeyL's point, the CopyFiles target does get executed. But the Copy task doesn't copy the files from the exe\dll\lib folder to the exe\dll\ folder. I found this out by adding Message tasks before and after the Copy task.

1
How do you know that the CopyFiles target is not executed? Do you have the build log? You can use <Message..> to explicitly log that a target was executed.Sergey L
Cool. Didn't know I could use the Message to do that. Will figure out how to do that. Two ways that I know: 1) Lib files didn't get copied to the dll folder 2) I don't see the copy output in the msbuild command window.rds80

1 Answers

2
votes

I'm not sure why the "CopyFiles" target doesn't run the first time... but that didn't run the CopyFiles target after the UnzipDLL target.

The problem was ItemGroup. It need write inside Copy target.

The msbuild script should be:

  <Target Name="CopyFiles">
    <ItemGroup>
      <LibFiles Include="$(ReleasePath)\exe\dll\lib\**\*.*;$(ReleasePath)\exe\dll\lib\*.*" />
    </ItemGroup>
    <Copy SourceFiles="@(LibFiles)" DestinationFolder="$(ReleasePath)\exe\dll\%(RecursiveDir)" />   
  </Target>

When we use ItemGroup to handle the batch file out of target, MSBuild will preprocessed those files. When we execute our MSBuild scripts, targets unzip and Copy will be completed in a very short time, however, the actual completion of the unzip will be a few seconds delay. So the CopyFiles target is actually executed. But the Copy task doesn't copy the files(Because unzip has not yet been completed). That the reason why the copy task not executed at first time but executed at second time.

So, to resolve this issue, just need write ItemGroup inside copy target.