Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Projects dependencies between C# and C++ project, build order

If both project Alpha and project Beta are C# projects, we can set that Beta depends on Alpha and this results to following build order: 1) Alpha; 2) Beta

If project Alpha is C++ project, we cannot add reference from project Alpha to Beta because Visual Studio 2010 does not allow this. Actually we can hack csproj file with notepad, but it doesn't help. Bu we can right click on solution, choose Project Dependencies and say that Beta depends on Alpha.

Problem: MSBuild does not honor dependencies set in sln file and builds projects in wrong order - 1) Beta; 2) Alpha. Note, that Visual Studio honors build order.

How we can set build order for MSBuild between C# and C++ projects within same solution?

like image 486
Roman Avatar asked Dec 21 '11 17:12

Roman


1 Answers

Try adding your C++ project reference to the C# project after cleaning the solution. This works for me, although I stumbled on this "workaround" by pure chance.

To me it looks as if Visual Studio is checking the build product of the referenced project, and when it notices the incompatibility it will refuse to add the reference. If, however, the build product is not around to check (because you cleaned the solution), Visual Studio happily adds the reference.

I tested the resulting solution both in Visual Studio and on our TFS build server (which AFAIK uses MSBuild) and build dependencies were evaluated correctly in both cases.

In your question you also mention that manually editing the .csproj file didn't help. I cannot confirm this. I was able to add the following reference and again got a positive build result:

<ProjectReference Include="..\Foo\Foo.vcxproj">
  <Name>Foo</Name>
  <ReferenceOutputAssembly>false</ReferenceOutputAssembly>
  <Private>False</Private>
</ProjectReference>

I am adding the ReferenceOutputAssembly element because this blogs.msdn.com article suggests it. In my experience, though, the build also works without the element. The article is still worth reading because it explains why MSBuild does not honor dependencies defined in the solution.

For completeness sake: I am running Visual Studio 2010, Version 10.0.40219.1 SP1Rel.

like image 187
herzbube Avatar answered Nov 15 '22 05:11

herzbube