1 minute read

If you are building a C++ library, leveraging “build event” is very useful to organize your output directory.

ex)

xcopy /Y /F /D "$(TargetDir)$(TargetName).dll" "$(ProjectDir)..\Output\bin\$(PlatformTarget)\$(Configuration)\"
xcopy /Y /F /D "$(TargetDir)$(TargetName).lib" "$(ProjectDir)..\Output\lib\$(PlatformTarget)\$(Configuration)\"
xcopy /Y /F /D "$(TargetDir)$(TargetName).pdb" "$(ProjectDir)..\Output\pdb\$(PlatformTarget)\$(Configuration)\"

xcopy document

Additional hacks

  1. If you don’t want to see the copy messages all the time, add 1>nul

It will show you messages only when an error occured.

xcopy /Y /F /D "$(TargetDir)$(TargetName).dll" "$(ProjectDir)..\Output\bin\$(PlatformTarget)\$(Configuration)\" 1>nul
  1. Force copy

Sometimes you might want to make sure the library is being built and build event copies all the binaries correctly.

This usually happens to me when I have separate libraries for testing and there is an another main program that pulls the library binaries out. But as you know well, build event only gets fired when the project is “actually being updated”.

If you want to copy the libraries anytime, by disabling auto up-to-date check, you can put this line in .vcproj file under PropertyGroup Global.

<PropertyGroup Label="Globals">
  ...
  <DisableFastUpToDateCheck>true</DisableFastUpToDateCheck>
</PropertyGroup>

Then you don’t have to keep typing spacebar and deleting to copy your main application code.

A boolean value that applies to Visual Studio only. The Visual Studio build manager uses a process called FastUpToDateCheck to determine whether a project must be rebuilt to be up to date. This process is faster than using MSBuild to determine this. Setting the DisableFastUpToDateCheck property to true lets you bypass the Visual Studio build manager and force it to use MSBuild to determine whether the project is up to date.

Reference:Always run post build event commands in visual studio 2017

Happy hacking!

Leave a comment