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

4

51

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.

Mentholated answered 21/12, 2009 at 1:5 Comment(0)
L
67

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.

Latterly answered 21/12, 2009 at 8:48 Comment(3)
I don't see any Outputs setting for a Custom Build Step. Where do you find the OutputsRamrod
I used this general concept to use Exec in an AfterBuild target to delete the output files, like so <Exec Command="del &quot;$(outputpath)$(assemblyname).*&quot;"></Exec>Christlike
Oh my, how should one know that without StackOverflow?! Here, on MSDN, is some additional information about the execution order of build steps and build events: msdn.microsoft.com/en-us/library/e85wte0k.aspx For my case, I just moved my "Post-Build Event" to the "Custom Build Step" and specified a filename in "Outputs" which does not exist. This reliably executes the custom build step even if the project is up-to-date.Doyle
E
9

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>

Earreach answered 3/4, 2018 at 20:58 Comment(0)
C
1

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

Contemplative answered 3/5, 2019 at 14:2 Comment(2)
Tried this, this alone does not work. What worked was diegoapereza's answer in combination with this setting.Laplante
I ran into the same issue as Doc Brown. If I update this setting, and I add <DisableFastUpToDateCheck>true to a <PropertyGroup>, the the task runs every time.Oldfangled
V
0

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?

Vistula answered 21/12, 2009 at 1:13 Comment(1)
By "the COM registration information may not be up-to-date", I mean the information in the registry may have changed, not that in the .rgs file. I'd like the post-build step to restore the information in the registry to what it should be according to the .rgs.Mentholated

© 2022 - 2024 — McMap. All rights reserved.