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?
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With