How to use external build system for Visual C++ 2013 project?

心已入冬 提交于 2019-12-03 08:30:49

You might want to look into Visual Studio's makefile projects (in the Visual C++/General project templates category).

You get to specify what commands to execute for each type of build (clean, build, rebuild). The command can invoke a make, run a batch file, or invoke some other build tool. It just executes a command. The commands can contain various macros that VS provides (similar to environment variables) so the command can be parametrized for things like making a target directory based on the solution or project name or type (debug vs. release).

(Michael Burr's reply pointed out a better direction, i.e. a better VC++ project template. You can combine my answer and his.)

Finally, I solved this issue!

The trick is the so-called target overriding. The Visual Studio context menu items Build\Rebuild\Clean correspond to MSBuild targets named Build\Rebuild\Clean, respectively. We just need to override them in the *.vcxproj file.

Such as this:

DO REMEMBER that:

The last target seen by MSBuild is the one that is used — this is why we put the at the end of the existing *.vcxproj file.

And in the override.proj, do whatever you like as below:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Target Name="Build">
    <Message Text="Build override!" />
    <Exec Command="kickass.bat" />
  </Target>
</Project>

The following 2 links are good reference:

  1. Hack the build

  2. Hijacking the Visual Studio Build Process

Note that:

  • The 1st link take a CSharp project as example, but ALSO works with VC++ project.

  • The 2nd link doesn't work for VC++ project but the rational is similar. If you didn't include the Microsoft.Cpp.targets, you will see the following error when loading the project:

ADD 1

As I tried, we don't need another overrride.proj file. We can just place the specific target at the end of the *.vcxprj file. Such as below:

ADD 2

With target overriding mentioned above, I can run my customized bat file with project's Build/Rebuild/Clean commands. But I noticed that when I run solution's Build/Rebuild/Clean commands, I think it is just following some kind of project dependency order to build each project respectively, which is not exactly equivalent to what I want for an overall build in my scenario.

My current workaround is to create a dummy project and use it to trigger a batch for my overall build.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!