none
MSBuild build order does not respect Project Dependencies build order RRS feed

  • Question

  • In Visual Studio 2019 I can get the build order from the build order tab in the Project Dependencies dialog for my solution.  The build order here makes sense.

    However, when MS Build does the actual build it breaks this build order, and it does so in a way that breaks the build.

    I assume that we have our builds set up for building more than one project at a time because it kicks off five projects builds at once (as seen from the top of the text sent to the output window).  The problem is that two of those five projects require another project that isn't even listed in that initial list to be built.  At least something in Visual Studio knows this to be true because I can see it graphically displayed in the really nice Architecture view (right click solution, select "Show Project Dependency Diagram").  It's also represented in the project references and once again in the Project Dependencies diagram.

    I'm hoping that it isn't because I'm using Visual Studio 2015 project files (and tools) with Visual Studio 2019.  Upgrading the code (which is still .net 35) isn't going to happen soon because of a dependency on control hardware that is still running CE 6.

    Any ideas on what is going wrong and how to fix it or is there a patch I can apply?

    Thanks,

    Andy


    Tuesday, September 10, 2019 4:46 PM

All replies

  • Hi Andrew,

    Did all your projects in the same solution? 

    l have tried to reproduce your issue. l create a solution with three projects when l add the build order in the build dependencies. l think you just build one of the project in VS IDE and it also build the projects which it depends, but in MSBuild it will ignore the projects it depends on. 

    It seems that MSBuild will not support project dependencies in the solution and do not scan project dependencies in the solution. So we suggest you can implement this by manually adding a projectreference in the project file.

    Such as:

    >>>>>First please clear the project dependencies in the solution

    If project a depends on project b, you can add this codes in a.csproj file

     <ItemGroup>
    <ProjectReference Include="D:\XX\XX\b.csproj">
        <ReferenceOutputAssembly>false</ReferenceOutputAssembly>
    </ProjectReference>
    </ItemGroup>

    So when you build project a in by MSBuild, it will build project b first.

    More information you can refer to this:

    https://devblogs.microsoft.com/visualstudio/incorrect-solution-build-ordering-when-using-msbuild-exe/

    Hope it could help you.

    Best Regards,

    Perry


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com




    Wednesday, September 11, 2019 4:27 AM
  • Hi Andrew,

    Did your issue solve or do you have any updates? If there are still any questions about this issue, please let us know in time so that we can help you further. If my reply is helpful for you to solve your issue, please remember to mark it as answer.

    Thanks for your understanding.

    Best Regards,

    Perry


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com

    Thursday, September 12, 2019 7:03 AM
  • Hi Andrew,

    Any update for this issue?

    >>I'm hoping that it isn't because I'm using Visual Studio 2015 project files (and tools) with Visual Studio 2019. 

    What does the tools you mean? Assuming you use project dependencies to manage the build order, if so, please make sure your command-line arguments looks similar to: msbuild xx.sln ... instead of msbuild xx.csproj.

    1. Since the project dependencies are defined in xx.sln file instead of xx.csproj file, if you use command like msbuild xx.csproj, msbuild has no access to the project dependencies defined in solution file, then the build order would break.

    2. Make sure you're using the msbuild tool from VS2019(msbuild 16.0), instead of that one from VS2015(msbuild 14.0), as I know the msbuild 14.0 can't recognize the project dependencies well.

    Path of  msbuild 16.0:  C:\Program Files (x86)\Microsoft Visual Studio\2019\vs Editon\MSBuild\Current\Bin. Or you can run the msbuild script in Developer Command prompt for VS2019 to test the build result.

    3. When you build in VS, it has a setting to control parallel project builds. In command-line, you can set -m:1 to make sure msbuild will build your project one by one. See this.

    Hope it makes some help.

    Best Regards

    Lance


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, September 17, 2019 10:27 AM