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

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


当前回答

我使用.bat文件和这个命令来做到这一点。

for /f %%F in ('dir /b /ad /s ^| findstr /iles "Bin"') do RMDIR /s /q "%%F"
for /f %%F in ('dir /b /ad /s ^| findstr /iles "Obj"') do RMDIR /s /q "%%F"

其他回答

我找到了这条线,然后赢了。再搜索一下就找到了这个power shell脚本:

Get-ChildItem .\ -include bin,obj -Recurse | ForEach-Object ($_) { Remove-Item $_.FullName -Force -Recurse }

或者更简洁:

gci -include bin,obj -recurse | remove-item -force -recurse

考虑到我在这里找不到答案,我想我应该分享一下。

“干净”还不够好吗?注意,您可以使用/t:clean从命令行调用msbuild。

http://vsclean.codeplex.com/

查找Visual的命令行工具 工作室解决方案和运行清洁 指挥他们。这可以让你清洁 打开所有这些的/bin/*目录 你手头的旧项目 你的硬盘

考虑到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 }

实际上,你可以进一步使用PS的建议,在项目目录中创建一个vbs文件,就像这样:

Option Explicit
Dim oShell, appCmd
Set oShell  = CreateObject("WScript.Shell")
appCmd      = "powershell -noexit Get-ChildItem .\ -include bin,obj -Recurse | foreach ($_) { remove-item $_.fullname -Force -Recurse -WhatIf }"
oShell.Run appCmd, 4, false

为了安全起见,我包含了-WhatIf参数,所以如果在第一次运行时对列表感到满意,可以删除它。