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

是否有一种快速的方法来实现这一点(例如使用.bat文件),而不必编写。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 }

其他回答

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

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

http://vsclean.codeplex.com/

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

注意:这是一个老答案,可能需要在VS 2019和一些obj工件的新版本中进行调整。在使用这种方法之前,请确保VS不需要在目标和输出目录中成功构建任何东西。

像这样的东西应该以一种非常优雅的方式完成,在干净的目标之后:

<Target Name="RemoveObjAndBin" AfterTargets="Clean">
    <RemoveDir Directories="$(BaseIntermediateOutputPath)" />
    <RemoveDir Directories="$(TargetDir)" />
</Target>

这招对我很管用:

for /d /r . %%d in (bin,obj) do @if exist "%%d" rd /s/q "%%d"

根据superuser.com上的答案

对我来说什么都没用。我需要删除bin和obj文件夹中的所有文件进行调试和发布。我的解决方案:

1.右击项目,卸载,右击再次编辑,到底部

2.插入

<Target Name="DeleteBinObjFolders" BeforeTargets="Clean">
  <RemoveDir Directories="..\..\Publish" />
  <RemoveDir Directories=".\bin" />
  <RemoveDir Directories="$(BaseIntermediateOutputPath)" />
</Target>

3.保存,重新加载项目,右键单击清洁和立即。