1

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.)

0

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

4 Comments

And indeed: It seemed to work nicely at first, only to break with a full build run, because MSBuild then actually detected a cyclic dependency, that I wanted to work around with this. So in my case it didn't work after all, and a ProjectReference should be done (which can't at the moment). I despise solution dependencies, they are horrible to maintain if the software project contains more than one solution. Go go go for ProjectReference - but first I'll need to clean up the project structure here.
Btw.: Do you consider using the MSBuild task inside a vcxproj a "hack" as such, or only when a ProjectReference should have worked?
Hi. I would consider using a MSBuild task inside a .vcxproj a hack at all times. Much worse than biting the bullet and using a solution dependency. As bad as Solutions (*.sln) are, they are better than this.
Thanks. I'm not so sure: my approach failed, but given the amount of manual customization we have to use to support our project files across different contexts, it seems an MSBuild task isn't that far fetched. Oh my. Maybe I can come up with a decent q. wrt. this over at softwareengineering.SE, but atm. its all a bit fuzzy. Cheers.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.