Visual Studio: Run C++ project Post-Build Event even if project is up-to-date

C++Visual StudioPost Build-EventRegsvr32

C++ Problem Overview


In Visual Studio (2008) is it possible to force the Post-Build Event for a C++ project to run even if the project is up-to-date?

Specifically, I have a project which builds a COM in-process server DLL. The project has a post-build step which runs "regsvr32.exe $(TargetPath)". This runs fine on a "Rebuild", but runs on a "Build" only if changes have been made to the project's source.

If I do a "Build" without making any changes, Visual Studio simply reports that the project is up-to-date and does nothing - the Post-Build Event is not run. Is there any way that I can force the Event to run in this situation? This is necessary since although the DLL itself is up-to-date, the registration information may not be.

C++ Solutions


Solution 1 - C++

You can use the Custom Build Step property page to set up a batch file to run. This runs if the File specified in the Outputs setting is not found, or is out-of-date. Simply specify some non-existent file there, and the custom build step will always run. It will run even if your project is up-to-date, since the Output file is never found.

Solution 2 - C++

Use this DisableFastUpToDateCheck

See an example:

<PropertyGroup>
    <PostBuildEvent>IF  EXIST C:\Projects\Copy_Files_To_Instance.ps1 ( powershell -file C:\Projects\Copy_Files_To_Instance.ps1)</PostBuildEvent>
    <DisableFastUpToDateCheck>true</DisableFastUpToDateCheck>

Solution 3 - C++

The registration information is determined largely by what's in the .rgs file. If that file changes the project will get built. I am not sure how else COM registration can change without making the project dirty. Do you mind providing more details about your particular situation?

Solution 4 - C++

In Visual Studio 2017 (perhaps other versions as well), for C# projects (haven't checked for C++ projects per OP's actual question) there is an option for "Run the post-build event:", and one option is "Always", which will run the Post-Build even if nothing has changed, rather than simply reporting that the project is up to date:

enter image description here

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser200783View Question on Stackoverflow
Solution 1 - C++TarydonView Answer on Stackoverflow
Solution 2 - C++diegoaperezaView Answer on Stackoverflow
Solution 3 - C++Igor ZevakaView Answer on Stackoverflow
Solution 4 - C++BRebeyView Answer on Stackoverflow