Search code examples
visual-studiovisual-c++pragmarebuild

MSVC: pragma to force rebuild of a file?


Is there a pragma-statement for MSVC that causes the compiler to rebuild a file always - also in case it thinks it was just builded?


Solution

  • Here is a trick that I use to achieve this :

    1) Add a post build step command with something like

    echo #define __FORCE_REBUILD__ "Include this file in a cpp to invalidate it at each compilation" > $(ProjectDir)ForceRebuild.h
    

    2) Add a '#include "ForceRebuild.h"' in each cpp that you want to force rebuild.

    It will only work after a build actually occurs (since the post build is skipped if Visual Studio decides to skip building the project).