Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MSBuild Copy task not copying files the first time round

Tags:

msbuild

I created a build.proj file which consists of a task to copy files that will be generated after the build is complete. The problem is that these files are not copied the first time round and I have to run msbuild again on the build.proj so that the files can be copied. Please can anyone tell me whats wrong with the following build.proj file:

<Configuration Condition="'$(Configuration)' == ''">Debug</Configuration>

<SourcePath Condition="'$(SourcePath)' == ''">$(MSBuildProjectDirectory)</SourcePath> 

<BuildDir>$(SourcePath)\build</BuildDir>

</PropertyGroup> 

<ItemGroup> 
    <Projects 
       Include="$(SourcePath)\src\myApp\application.csproj">  
    </Projects> 
</ItemGroup> 

<Target Name="Build">
   <Message text = "Building project" />    
   <MSBuild   
     Projects="@(Projects)" 
     Properties="Configuration=$(Configuration)" /> 
</Target>

<ItemGroup>
   <OutputFiles Include ="$(MSBuildProjectDirectory)\**\**\bin\Debug\*.*"/>
</ItemGroup>

<Target Name="CopyToBuildFolder">
   <Message text = "Copying build items" />
   <Copy SourceFiles="@(OutputFiles)" DestinationFolder="$(BuildDir)"/>
</Target>

<Target Name="All"
   DependsOnTargets="Build; CopyToBuildFolder"/>

</Project> 
like image 217
Draco Avatar asked Mar 03 '09 14:03

Draco


Video Answer


1 Answers

The itemgroups are evaluated when the script is parsed. At that time your files aren't there yet. To be able to find the files you'll have to fill the itemgroup from within a target.

  <!-- SQL Scripts which are needed for deployment -->
  <Target Name="BeforeCopySqlScripts">
    <CreateItem Include="$(SolutionRoot)\04\**\Databases\**\*.sql">
      <Output ItemName="CopySqlScript" TaskParameter="Include"/>
    </CreateItem>
  </Target>

This example creates the ItemGroup named "CopySqlScript" using the expression in the Include attribute.

Edit:

Now I can read your script: add the CreateItem tag within your CopyToBuildFolder target

like image 119
thijs Avatar answered Sep 24 '22 23:09

thijs