Question

Explicitly setting dependency in VS2010 between unmanaged C++ project and C# project is honored in VS2010, but dependency is ignored in MSBuild 4.0.

It is impossible to add a reference to unmanaged C++ project from C# project, afaik.

How do i ensure correct build order if a solution contains unmanaged and managed projects?

Was it helpful?

Solution

MSBuild has a bug in it and doesn't correctly honor project dependencies added at the solution level. Take a look at http://social.msdn.microsoft.com/Forums/en-US/msbuild/thread/80cc6447-b720-4806-8395-7c257b207613/ and https://connect.microsoft.com/VisualStudio/feedback/details/613284/msbuild-4-does-not-respect-build-order-when-building-a-solution

A posting by Microsoft on the connect page indicates that its a bug in the 64-bit version of MSBuild. Try switching to the 32-bit version to see if that solves the problem.

If you can't do that, or it doesn't work, there are two other options. Neither of them are ideal.

The first option would be to manually edit the SLN file and change the order the projects appear in the file to match the build order you want. I imagine Victor's solution would be a much better idea, since additional changes to the solution file could end up overwriting the changes again.

The second option would be to manually export the MSBuild "metaproject" for the solution and edit the build order directly and add any other customizations you need. From what I've read, even at Microsoft they don't "dogfood" solution compilation - instead, they avoid them completely during builds and use custom MSBuild files instead.

To generate the metaproj, set the environment variable MSBuildEmitSolution to 1. After running MSBuild on the solution and you should see a ".metaproj" file in the same directory - it contains the script that MSBuild generates in-memory to compile the solution. You should be able to make the necessary edits, check it in, then set the build server to compile it.

The issue will disappear in the next release of Visual Studio. The Microsoft Connect page has a posting from Microsoft that it will be fixed in the next release, and rumor has it they're getting rid of .sln files and replacing them with proper MSBuild projects.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top