msbuild - 如何使用msbuild删除所有文件和文件夹

标签 msbuild

如何删除给定路径中的所有文件和文件夹?

我尝试过此操作,但无法选择目录。

<Target Name="CleanSource" Condition="$(path)!=''">

    <Message Text="path=$(path)"/>

    <ItemGroup>
      <fileToDelete Include="$(path)\**\*.*" />
      <directoryToDelete Include="$(path)\**\" /><!these doest not select any directory at all-->     
    </ItemGroup>

    <Message Text="file to delete:@(fileToDelete)"/>
    <Message Text="directory to delete:@(directoryToDelete)"/>

    <Delete Files="@(fileToDelete)" />
    <Message Text="file effectively deleted:@(DeletedFiles)"/>
    <RemoveDir Directories="@(directoryToDelete)" />
    <Message Text="Directory effectively deleted:@(RemovedDirectories)"/>

</Target>

最佳答案

RemoveDir task删除指定的目录及其所有文件和子目录。您不必先删除文件和子目录。只需将目录名称传递给RemoveDir即可。

   <ItemGroup>
        <DirsToClean Include="work" />
    </ItemGroup>
    <Target Name="CleanWork">
        <RemoveDir Directories="@(DirsToClean)" />
    </Target>

关于msbuild - 如何使用msbuild删除所有文件和文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5080856/

相关文章:

visual-studio - 必须安装WiX Toolset v3.11(或更高版本)构建工具才能构建此项目

c# - 如何在 dotnet pack nuget 包中包含来自构建输出 (dacpac) 的非 dll 文件?

windows - 即使启用 Windows 长路径,ALINK 错误 1065

.net - “dotnet Restore”与 TeamCity 中的 'nuget restore'

visual-studio - 在构建时运行 Visual Studio 自定义工具

visual-studio - 在 Visual Studio 2015 下安装 Platform Toolset v120

visual-studio - 抑制单个编译器错误(例如 NU1603)

c# - 在 VSTS 上构建 MonoGame 项目

msbuild - 如何使用 MSBuild 避免使用 MSDeploy 到文件系统的这种深层文件夹结构?

MSBuild exec 任务,退出代码为空