dotnet/msbuild

MSB5009 May Not Fire In All Conditions

Open

#4,835 创建于 2019年10月21日

在 GitHub 查看
 (2 评论) (0 反应) (0 负责人)C# (1,364 fork)batch import
Area: DebuggabilityArea: Solution (.sln)help wantedtriaged

仓库指标

Star
 (5,062 star)
PR 合并指标
 (平均合并 11天 7小时) (30 天内合并 125 个 PR)

描述

Steps to reproduce

Consider the attached solution/project.

MS5009BadNestedSolutionEntries.zip

Pay special attention to the MS5009BadNestedSolutionEntries.sln, specifically the NestedProjects section:

	GlobalSection(NestedProjects) = preSolution
		{1484A47E-F4C5-4700-B13F-A2BDB6ADD35E} = {5EE89BD0-04E3-4600-9CF2-D083A77A9449}
		{1484A47E-F4C5-4700-B13F-A2BDB6ADD35E} = {5EE89BD0-04E3-4600-9CF2-D083A77A9448}
	EndGlobalSection

In this example a developer has inadvertently merged in a bad NestedProject line (probably due to a merge conflict). The project {5EE89BD0-04E3-4600-9CF2-D083A77A9449} is invalid as per the Solution file.

MSBuild reports no issue with the file and Visual Studio will happily load it with the correct nesting:

image

Now consider a normalization tool (such as this one here: https://github.com/aolszowka/VisualStudioSolutionSorter) which sorts this such that the section now looks like this:

	GlobalSection(NestedProjects) = preSolution
		{1484A47E-F4C5-4700-B13F-A2BDB6ADD35E} = {5EE89BD0-04E3-4600-9CF2-D083A77A9448}
		{1484A47E-F4C5-4700-B13F-A2BDB6ADD35E} = {5EE89BD0-04E3-4600-9CF2-D083A77A9449}
	EndGlobalSection

Attempting to build this via MSBuild now invokes the following:

MS5009BadNestedSolutionEntries.sln : Solution file error MSB5009: Error parsing the nested project section in solution file.

The MSB5009 error is correct in this case.

The one who will end up throwing the error is https://github.com/microsoft/msbuild/blob/e0116872ef1bf48f1f527d69de64ad58cb7453e0/src/Build/Construction/Solution/ProjectInSolution.cs#L371-L372

Opening the solution file in Visual Studio still loads, but the folder nesting is broken as expected:

image

Expected behavior

We would expect MSB5009 to trigger in all cases where invalid entries have been added into the NestedProject section.

Actual behavior

MSB5009 is only triggered when it is the LAST Nested Project Reference for this project.

Environment data

msbuild /version output:

Microsoft (R) Build Engine version 15.9.21+g9802d43bc3 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.

15.9.21.664

OS info: Windows 10 Enterprise 1903 (OS Build 18362.357)

贡献者指南