Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Projects skipped when missing EndProject #5808

Merged

Conversation

BartoszKlonowski
Copy link
Contributor

This pull request fixes: #5027

Changes introduced in this PR covers the case where having a project without EndProject label, next projects contained in this malformed solution .sln file are not built.
So this PR adjusts the behavior of MSBuild to the Visual Studio (please see #5027 (comment))


Changes done in this delivery are:

  • Add new case to project's parsing procedure where the next line read in the project's configuration (in malformed .sln file) is any of project's configuration detail, nor EndProject label, but is in fact the beginning of new project's configuration.
  • Recursively read the next spotted project (which is incorrectly nested in the one missing it's EndProject label) and add it to parsed projects
  • Cover two scenarios with missing EndProject label:
    One for only one incorrectly nested project
    One for multiple projects missing EndProject

NOTE: Recursive approach was necessary, due to impossibility of going one line back in the stream being already read, which means that when new "Project(" is spotted instead of "EndProject", it's already too late for the normal procedure to notice the next "Project(". There is a Peek() method available, which allows to see the next single character without actually reading it, but this approach would require bigger refactor, while recursive approach is now tested and verified working well.

When reading the solution .sln file each project is parsed by catching
the "Project(" sequence, and the parsing is stopped when reaching the
EndProject label.
However, in case of having the solution file malformed
(see: )
it is possible, that one of projects won't have it's EndProject label,
so originally it will be the only one being added to the projects list.

To avoid such situation, new condition has been added to the project's
parsing procedure, which responsibility is to check against additional
"Project(" sequence BEFORE meeting EndProject.
This situation indicates malformed solution file.

To handle this situation, additional 'else if' statement logs the
warning and recursively starts to parse another project.
When getting back from reading incorrectly nested project, the original
project's parsing procedure is stopped and whole procedure continues.
Two unit tests are added to cover the case with missing EndProject in an
invalid solution file:

ParseNextProjectContainedInInvalidSolutionEvenWhenMissingEndProject -
which is to check for a case with one project after missing EndProject,
ParseAllProjectsContainedInInvalidSolutionEvenWhenMissingEndProject -
which is to check for a case with more than just one project after
missing EndProject

Both these tests should simply check whether each project, potentially
skipped due to missing EndProject label, is correctly found in the
solution file and is parsed correctly by recursive approach.
Copy link
Member

@Forgind Forgind left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice! Thank you!

The unit test checking whether incorrectly nested project in malformed
solution file (when first project missing it's EndProject label) is
correctly found and parsed is redundant.
The other unit test checking similar case (several projects nested under
the one missing EndProject) is the superset of the first one, which
makes the first one unnecessary.
@Forgind
Copy link
Member

Forgind commented Oct 29, 2020

Failing test looks like the problematic one improved by #5827. Reran it.

Copy link
Member

@rainersigwald rainersigwald left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks!

@Forgind Forgind merged commit b41ff04 into dotnet:master Oct 30, 2020
@rainersigwald
Copy link
Member

Thanks, @BartoszKlonowski!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

MSBuild skips building a project in the solution at all due to overly permissive parsing of the solution file.
4 participants