I want to delete all bin and obj folders to force all projects to rebuild everything

后端 未结 26 1956
迷失自我
迷失自我 2020-11-28 16:53

I work with multiple projects, and I want to recursively delete all folders with the name \'bin\' or \'obj\' that way I am sure that all projects will rebuild everything (so

相关标签:
26条回答
  • 2020-11-28 17:35

    I wrote a powershell script to do it.

    The advantage is that it prints out a summary of deleted folders, and ignored ones if you specified any subfolder hierarchy to be ignored.

    Output example

    0 讨论(0)
  • 2020-11-28 17:38

    Something like that should do it in a pretty elegant way, after clean target:

    <Target Name="RemoveObjAndBin" AfterTargets="Clean">
        <RemoveDir Directories="$(BaseIntermediateOutputPath)" />
        <RemoveDir Directories="$(TargetDir)" />
    </Target>
    
    0 讨论(0)
  • 2020-11-28 17:40

    I found this thread and got bingo. A little more searching turned up this power shell script:

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

    I thought I'd share, considering that I did not find the answer when I was looking here.

    0 讨论(0)
  • 2020-11-28 17:40

    I use to always add a new target on my solutions for achieving this.

    <Target Name="clean_folders">
      <RemoveDir Directories=".\ProjectName\bin" />
      <RemoveDir Directories=".\ProjectName\obj" />
      <RemoveDir Directories="$(ProjectVarName)\bin" />
      <RemoveDir Directories="$(ProjectVarName)\obj" />
    </Target>
    

    And you can call it from command line

    msbuild /t:clean_folders
    

    This can be your batch file.

    msbuild /t:clean_folders
    PAUSE
    
    0 讨论(0)
  • 2020-11-28 17:40

    This is my batch file that I use for deleting all BIN and OBJ folders recursively.

    1. Create an empty file and name it DeleteBinObjFolders.bat
    2. Copy-paste code the below code into the DeleteBinObjFolders.bat
    3. Move the DeleteBinObjFolders.bat file in the same folder with your solution (*.sln) file.
    @echo off
    @echo Deleting all BIN and OBJ folders...
    for /d /r . %%d in (bin,obj) do @if exist "%%d" rd /s/q "%%d"
    @echo BIN and OBJ folders successfully deleted :) Close the window.
    pause > nul
    
    0 讨论(0)
  • 2020-11-28 17:41

    Have a look at the CleanProject, it will delete bin folders, obj folders, TestResults folders and Resharper folders. The source code is also available.

    0 讨论(0)
提交回复
热议问题