locked
how to remove directories recursively? RRS feed

  • Question

  • Hi,

    I have a huge list of solutions and project, which generate the websites folder under '_PublishedWebSites', and each individual websites has its own BIN folder which contains the binaries, these binaries also exist on the root folder of 'Release', hence there is no requirement of having all these BIN folders and any files in these folders to each websites, is there any easy way to delete these folders thru Team Build, I had tried following in my proj file, but it didnt worked:

    <ItemGroup>
    <
    BinDirectory Include="$(BinariesRoot)\Release\_PublishedWebsites\**\Bin" />
    </
    ItemGroup>
    <
    Target Name="BeforeDropBuild">
    <
    RemoveDir Directories="@(BinDirectory)" />
    </
    Target>

    the total size of the publishedwebsites folder exceed to 4GB, with all these BIN folder. any suggestion?


    MK
    Monday, August 24, 2009 11:46 PM

Answers

  • Hi MK

    We raely override core build targets in the team build project file. See Customizable Team Foundation Build Targets for more information. When I made the first reply, I didn't find a better approach. Mike Fourie suggested 2 better solutions:

    One is to set SkipDropBuild property to true and the build agent will not execute targests like CoreDropBuild. We can then override the AfterCompile target and copy output files to the drop location with the below script:
      <Target Name="AfterCompile">
        <ItemGroup>
          <FilesToCopy Include="$(BinariesRoot)\**\*.*" 
                       Exclude="$(BinariesRoot)\**\_PublishedWebsites\**\bin\*.*"/>
        </ItemGroup>
    
        <Copy Condition=" '$(BuildBreak)'!='true' "
              SourceFiles="@(FilesToCopy)"
              DestinationFiles="@(FilesToCopy ->'$(DropLocation)\$(BuildNumber)\%(RecursiveDir)%(Filename)%(Extension)')" />
    
        <Copy Condition=" '$(BuildBreak)'=='true' "
              SourceFiles="@(FilesToCopy)"
              DestinationFiles="@(FilesToCopy ->'$(DropLocation)\$(BuildNumber)\%(RecursiveDir)%(Filename)%(Extension)')"
              ContinueOnError="true" />
      </Target>


    Another approach is that we can use FindUnder MSBuild task to find out all bin folders and save them in an item group, then use RemoveDir task to remove all the bin folders. Let us know if you have any questions.


     

    Bill Wang

    MSDN Subscriber Support in Forum

    If you have any feedback on our support, please contact msdnmg@microsoft.com 


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Proposed as answer by Bill.Wang Tuesday, September 1, 2009 5:22 AM
    • Marked as answer by Bill.Wang Thursday, September 3, 2009 9:12 AM
    Tuesday, August 25, 2009 10:22 AM

All replies

  • Hi MK

    If I'm correct, the MSBuild item group can't include folders. Since your solution is perty large. I would not delete binary files from the $(BinariesRoot) folder. Otherwise, it may require more time in the next build if you have enabled incremental build.

    Instead, you can override the CoreDropBuild target like the below. The Exclude attribute should exclude all files in the Bin folders.

     <Target Name="CoreDropBuild"
            Condition=" '$(SkipDropBuild)'!='true' and '$(IsDesktopBuild)'!='true' "
            DependsOnTargets="$(CoreDropBuildDependsOn)" >
    
        <ItemGroup>
          <FilesToCopy Include="$(BinariesRoot)\**\*.*" 
                       Exclude="$(BinariesRoot)\**\_PublishedWebsites\**\bin\*.*"/>
        </ItemGroup>
    
        <Copy Condition=" '$(BuildBreak)'!='true' "
              SourceFiles="@(FilesToCopy)"
              DestinationFiles="@(FilesToCopy ->'$(DropLocation)\$(BuildNumber)\%(RecursiveDir)%(Filename)%(Extension)')" />
    
        <Copy Condition=" '$(BuildBreak)'=='true' "
              SourceFiles="@(FilesToCopy)"
              DestinationFiles="@(FilesToCopy ->'$(DropLocation)\$(BuildNumber)\%(RecursiveDir)%(Filename)%(Extension)')"
              ContinueOnError="true" />
    
      </Target>


    Just for fun, if you have installed Windows PowerShell in the build agent, you can delete all bin folders in the drop directory with the below script:
      <Target Name="AfterDropBuild">
        <Message Text="Deleting Bin folders in the _PublishedWebsites directory" />
        <Exec Command="powershell &quot;get-childitem -path 
    \&quot;$(DropLocation)\$(BuildNumber)\*\_PublishedWebsites\*\bin\&quot; | remove-item -force -recurse&quot;" />
      </Target>

     

    Bill Wang

    MSDN Subscriber Support in Forum

    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Tuesday, August 25, 2009 4:18 AM
  • Hi MK

    One of my colleagues Mike Fourie has pointed out that we should not override the CoreDropBuild target. He also gave me other suggestions. I will make more research and reply you later.

    Bill Wang

    MSDN Subscriber Support in Forum

    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Tuesday, August 25, 2009 7:26 AM
  • Hi MK

    We raely override core build targets in the team build project file. See Customizable Team Foundation Build Targets for more information. When I made the first reply, I didn't find a better approach. Mike Fourie suggested 2 better solutions:

    One is to set SkipDropBuild property to true and the build agent will not execute targests like CoreDropBuild. We can then override the AfterCompile target and copy output files to the drop location with the below script:
      <Target Name="AfterCompile">
        <ItemGroup>
          <FilesToCopy Include="$(BinariesRoot)\**\*.*" 
                       Exclude="$(BinariesRoot)\**\_PublishedWebsites\**\bin\*.*"/>
        </ItemGroup>
    
        <Copy Condition=" '$(BuildBreak)'!='true' "
              SourceFiles="@(FilesToCopy)"
              DestinationFiles="@(FilesToCopy ->'$(DropLocation)\$(BuildNumber)\%(RecursiveDir)%(Filename)%(Extension)')" />
    
        <Copy Condition=" '$(BuildBreak)'=='true' "
              SourceFiles="@(FilesToCopy)"
              DestinationFiles="@(FilesToCopy ->'$(DropLocation)\$(BuildNumber)\%(RecursiveDir)%(Filename)%(Extension)')"
              ContinueOnError="true" />
      </Target>


    Another approach is that we can use FindUnder MSBuild task to find out all bin folders and save them in an item group, then use RemoveDir task to remove all the bin folders. Let us know if you have any questions.


     

    Bill Wang

    MSDN Subscriber Support in Forum

    If you have any feedback on our support, please contact msdnmg@microsoft.com 


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Proposed as answer by Bill.Wang Tuesday, September 1, 2009 5:22 AM
    • Marked as answer by Bill.Wang Thursday, September 3, 2009 9:12 AM
    Tuesday, August 25, 2009 10:22 AM