我与多个项目一起工作,我想递归删除所有名为“bin”或“obj”的文件夹,这样我就可以确保所有项目都会重新构建所有内容(有时这是迫使Visual Studio忘记所有以前的构建的唯一方法)。

是否有一种快速的方法来实现这一点(例如使用.bat文件),而不必编写。net程序?


当前回答

这对我来说很好: 开始/d /r。%%d in (bin,obj, ClientBin,Generated_Code) do @if exist "%%d" rd /s /q "%%d"

其他回答

我讨厌obj文件乱扔源代码树。我通常设置项目,以便它们在源树外输出obj文件。对于我通常使用的c#项目

 <IntermediateOutputPath>..\..\obj\$(AssemblyName)\$(Configuration)\</IntermediateOutputPath>

用于c++项目

 IntermediateDirectory="..\..\obj\$(ProjectName)\$(ConfigurationName)"

在添加到项目文件之前删除bin和obj:

<Target Name="BeforeBuild">
    <!-- Remove obj folder -->
    <RemoveDir Directories="$(BaseIntermediateOutputPath)" />
    <!-- Remove bin folder -->
    <RemoveDir Directories="$(BaseOutputPath)" />
</Target>

这是文章:如何删除bin和/或obj文件夹构建或部署之前

这对我来说很好: 开始/d /r。%%d in (bin,obj, ClientBin,Generated_Code) do @if exist "%%d" rd /s /q "%%d"

我认为你可以右键点击你的解决方案/项目,然后点击“清洁”按钮。

据我所知,它是这样工作的。我现在没有VS.NET,所以不能测试它。

考虑到PS1文件在currentFolder(你需要删除bin和obj文件夹的文件夹)中

$currentPath = $MyInvocation.MyCommand.Path
$currentFolder = Split-Path $currentPath

Get-ChildItem $currentFolder -include bin,obj -Recurse | foreach ($_) { remove-item $_.fullname -Force -Recurse }