0

I have a TFS MSBuild project from there I am trying to delete directories whose names I would not want to explicitly specify from MSBuild [Since they are many and may change in the future] but want to retain one directory.

In the below example I want to delete all folder under "Web" but want to retain "bin" directory.

-Web
    --bin
    --folder 1
    --folder 2
    --folder 3
    ...
    ...

    <ItemGroup>
  <OutputDirs Include="$(DropLocation)\$(BuildNumber)\Web\**\*.*" Exclude="$(DropLocation)\$(BuildNumber)\Web\bin" />
</ItemGroup> <RemoveDir Directories="@(OutputDirs)" />

The above example works for files but not Directories, is there a exclude option I can use without specifying directories that I want to include.

thanks in advance.

5
  • Doesnt seem to be any support in inbuilt task. You should backup the directory delete all and then restore it.
    – allen
    Feb 3, 2013 at 18:18
  • Try to change Include="$(DropLocation)\$(BuildNumber)\Web\**\*.*" to Include="$(DropLocation)\$(BuildNumber)\Web\**\*", because the *.* will commonly not find directories, because they usually don't have a dot in their name.
    – MikeR
    Feb 4, 2013 at 8:15
  • @Mike, I tried your suggestion, this still deletes all files under the folders but keeps the empty folders. I guess the only way to put some logic here is to invoke dos command line from within MSBuild. Any other suggestions appreciated.
    – user973374
    Feb 13, 2013 at 15:23
  • @allen, this adds so much extra time to the build that it is not worth the effort.
    – user973374
    Feb 13, 2013 at 15:28
  • If you can use a Contains, than you could iterate over OutputDirs and have a condition that it not includes web\bin\ . Here is discussed about the Contains stackoverflow.com/questions/3289538/…
    – MikeR
    Feb 13, 2013 at 16:38

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.