MSB5009 May Not Fire In All Conditions
- Dominant language
- C#
- Stars
- 5.5k
- Forks
- 1.5k
- Avg merge
- 1d 13h
- Merged PRs (30d)
- 133
Description
### Steps to reproduce
Consider the attached solution/project.
[MS5009BadNestedSolutionEntries.zip](https://github.com/microsoft/msbuild/files/3753057/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:

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:

### 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)
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.