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

后端 未结 26 1958
迷失自我
迷失自我 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:46

    Very similar to Steve's PowerShell scripts. I just added TestResults and packages to it as it is needed for most of the projects.

    Get-ChildItem .\ -include bin,obj,packages,TestResults -Recurse | foreach ($_) { remove-item $_.fullname -Force -Recurse }
    
    0 讨论(0)
  • 2020-11-28 17:47

    For the solution in batch. I am using the following command:

    FOR /D /R %%G in (obj,bin) DO @IF EXIST %%G IF %%~aG geq d RMDIR /S /Q "%%G"


    The reason not using DIR /S /AD /B xxx
    1. DIR /S /AD /B obj will return empty list (at least on my Windows10)
    2. DIR /S /AD /B *obj will contain the result which is not expected (tobj folder)

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

    I use .bat file with this commad to do that.

    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"
    
    0 讨论(0)
  • 2020-11-28 17:48

    A very quick and painless way is to use the rimraf npm utility, install it globally first:

    > npm i rimraf -g
    

    And then the command from your project root is quite simple (which can be saved to a script file):

    projectRoot> rimraf **/bin **/obj
    

    To optimize the desired effect you can leverage the project event targets (the one you could use is BeforeRebuild and make it run the previous command) which are specified in the docs: https://docs.microsoft.com/en-us/visualstudio/msbuild/how-to-extend-the-visual-studio-build-process?view=vs-2017

    I like the rimraf utility as it is crossplat and really quick. But, you can also use the RemoveDir command in the .csproj if you decide to go with the target event option. The RemoveDir approach was well explained in another answer here by @Shaman: https://stackoverflow.com/a/22306653/1534753

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

    On our build server, we explicitly delete the bin and obj directories, via nant scripts.

    Each project build script is responsible for it's output/temp directories. Works nicely that way. So when we change a project and add a new one, we base the script off a working script, and you notice the delete stage and take care of it.

    If you doing it on you logic development machine, I'd stick to clean via Visual Studio as others have mentioned.

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

    http://vsclean.codeplex.com/

    Command line tool that finds Visual Studio solutions and runs the Clean command on them. This lets you clean up the /bin/* directories of all those old projects you have lying around on your harddrive

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