When to use <ProjectReference> in project files?

Summary:

Projects are being built in the wrong order with visual studio and managed projects in C ++ and C #

Description:

I have a massive (100+ projects) solution file that creates multiple projects in the wrong order. The solution file contains the following project types:

  • native C / C ++
  • Managed C ++
  • Managed C #

The solution contains all the relevant dependencies between the various types of projects. So, when I build from the command line (using MSBuild), the problem arises. Managed project dependencies (both C ++ and C #) are created in the wrong order. For example, a project will not be created because there is no managed dependency. For example, a C ++ managed file will have a usage declaration that will fail:

#using <foo.dll> 

since foo.dll does not yet exist.

This means that foo.dll should have been created before, but it was not. As I mentioned earlier, dependencies are correctly configured in the solution file. For example, if foo depends on baz, I have this in the solution file ...

 Project("{C4ABA494-43D0-400A-9917-20E167A12CFD}") = "Foo", "...\Foo.vcxproj", "{5A42640E-9E0A-442B-8A40-AA91AD5444AC}" ProjectSection(ProjectDependencies) = postProject ... {2CE32AE0-B129-40BA-B06E-A628FA149AB3} = {2CE32AE0-B129-40BA-B06E-A628FA149AB3} EndProjectSection EndProject ... Project("{C4ABA494-43D0-400A-9917-20E167A12CFD}") = "baz", "...\baz.csproj", "{2CE32AE0-B129-40BA-B06E-A628FA149AB3}" ProjectSection(ProjectDependencies) = postProject ... EndProjectSection EndProject 

Therefore, the solution file correctly has a dependency. But the dependency in the Foo.vcxproj project is expressed only by the #using directive. I read in a visual studio blog that there is a known error when ordering projects in msbuild. http://blogs.msdn.com/b/visualstudio/archive/2010/12/21/incorrect-solution-build-ordering-when-using-msbuild-exe.aspx

Their job is to add an element that is called to my projects, for example:

 <ProjectReference Include="... foo.csproj"> <ReferenceOutputAssembly>false</ReferenceOutputAssembly> </ProjectReference> 

In any case, my question is : should this be done ONLY for my managed C ++ projects? Or am I doing this for managed C ++ and C # projects? (I believe that I do not need to do this for C # projects, since their dependencies are explicit)

Note. I tried to include this in ALL projects in my build, and it did not work so hot, since I had many strange build errors in my native projects ...

Thanks for any answer to this question.

+6
source share
1 answer

I had the same problem, but only with C # projects. It appears that MsBuild does NOT use application file dependencies. It uses project links inside project files to create build order. Try updating all your ProjectReferences to get the correct build order. In your case, you need to add a link to the managed project (dependency) in the C ++ project file.

The answer to your question: Yes, you should do this for both managed C ++ projects and C #. Defining dependencies inside a sln file is not enough if you are building using MSBuild.

+4
source

Source: https://habr.com/ru/post/905010/


All Articles