Clean the Visual Studio 2019 x64 Release or Debug build directory using Clean-Build.bat batch script. Place in the x64 directory and run the bat. Great if you need to archive your project before sending and don’t want to send a bunch of extra files. Tested with Visual Studio 2019 and 2022. The script can be expanded to remove other kinds of files.

Files Removed

File type Usage
*.ipdb Incremental Link-Time Code Generation - Program database (PDB) file
*.iobj Incremental Link-Time Code Generation - Object file
*.pdb Program database (PDB)
*.idb Intermediate debug file / state file used for minimal rebuild and incremental compilation
*.ilk Intermediary linker files
*.exp DLL exports
*.obj Object file - compiled code that the linker uses
*.tlog Used for incremental builds - information about all inputs / outputs
*.FileListAbsolute.txt List of files built in current build
*.recipe Used in Guidance Automation Toolkit

Notes

  • Important to use .\ before paths, otherwise it will execute from the drive’s root directory
  • If there is more than one condition that needs to be used an if statement then must use nested if statements
  • can use defined to check if a variable is defined or not defined if not defined.

Clean-Build.bat

@echo off
setlocal enableextensions
setlocal EnableDelayedExpansion

set ExecutableName=%1%
set BuildType=%2%

if not defined BuildType (
    echo Usage: Clean-Build.bat ExecutableName BuildType
    exit /b 1
)

if not "%BuildType%" == "Debug" (
    if not "%BuildType%" == "Release" (
        echo Usage: Clean-Build.bat ExecutableName BuildType
        echo Build must be Release or Debug
        exit /b 1
    )
)

if not defined ExecutableName (
    echo Usage: Clean-Build.bat ExecutableName BuildType
    exit /b 1
)

echo Cleaning:   %ExecutableName%
echo Build type: %BuildType%

:: Release builds
if "%BuildType%" == "Release" (
    del .\%BuildType%\*.iobj
    del .\%BuildType%\*.ipdb
)

:: Debug builds
if "%BuildType%" == "Debug" (
    del .\%BuildType%\*.ilk
    del .\%BuildType%\*.idb
)

:: Both builds
del .\%BuildType%\*.tlog
del .\%BuildType%\*.obj
del .\%BuildType%\*.recipe
del .\%BuildType%\*.pdb
del .\%BuildType%\*.log
del .\%BuildType%\*.FileListAbsolute.txt
rmdir /S /Q .\%BuildType%\%ExecutableName%.tlog

echo Done