简体   繁体   中英

Using MSBuild task to build another (C++) project in the same solution?

Du to a weird dependency chain that I cannot break at the moment, I would like to build one C++ project as a "post build" step from another C++ project in the very same solution.

I know how to invoke MSBuild on the command line, but I figured it might make more sense to use the built-in MSBuild task to just trigger the build on the other project:

my.vcxproj :

<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
...
  <Target Name="BuildTheOtherProject" AfterTargets="Build">  
      <MSBuild Projects="..\theother\theother.vcxproj" Targets="Build" Properties="Configuration=$(Configuration);Platform=$(Platform)">
      </MSBuild>  
  </Target>
</Project>

This seems to work fine on first glance, but will this continue to work (think: parallel project building of the full solution, etc.) and am I passing the correct values to the MSBuild task?

There is a related question that asks about the same thing for C# projects, and there seems to be a problem with csc (which is irrelevant for the vcxproj), so I'm wondering what the general stance is on this?

(I'm on Visual Studio 2015 atm.)

Yes you are invoking the MSBuild task correctly. But you should not do this. It's bad style. And you are sure to trip up someone in the future with this little trick that is hiding in the .vcxproj file. Specify the dependency the correct way: In the solution file (.sln) and visual studio will make sure that the file gets built in the correct order. If you want more power, you can specify the dependency using a <ProjectReference> instead of using a solution file, but that's a different topic.

In all my years of working at companies with very large code bases: A trick like this has never been done, and never should.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM