Solution Parser not working in .Net8

Sanjay Kumar Jha 151 Reputation points
2024-05-13T10:05:23.3933333+00:00

Hi,

I'm in the process of migrating my WPF application from .NET Framework 4.8 to .NET 8. In my previous application, I utilized the Solution Parser functionality from Microsoft.Build for certain tasks. However, after migrating to .NET 8, this functionality seems to be failing. To illustrate the issue, I've created a sample solution. I would appreciate it if you could take a look and help me identify the cause of the failure in .NET 8.

Project link:

"https://vemp-my.sharepoint.com/:u:/g/personal/sanjaykumarjha_virtualemployee_com/EfPl35xPuB1BlURE9aAP5XkBEG-SiJQXj7pHT6KEkjXadA?e=OStwpf"

Thanks,

Sanjay

Windows Forms
Windows Forms
A set of .NET Framework managed libraries for developing graphical user interfaces.
1,855 questions
Windows
Windows
A family of Microsoft operating systems that run across personal computers, tablets, laptops, phones, internet of things devices, self-contained mixed reality headsets, large collaboration screens, and other devices.
4,842 questions
Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,686 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,374 questions
Windows 11
Windows 11
A Microsoft operating system designed for productivity, creativity, and ease of use.
8,406 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Can Kucukgultekin 0 Reputation points
    2024-05-14T21:15:59.8266667+00:00

    I examined the project a little. I want to share a few things that caught my eye,

    1. Correct API Usage: The MSBuild API has changed, and directly loading a solution file using ProjectCollection.GlobalProjectCollection.LoadProject might not work. You should use the SolutionFile class from Microsoft.Build.Construction to parse the solution file.
    2. Check Compatibility: Ensure the versions of Microsoft.Build and Microsoft.Build.Locator are compatible with .NET 8.

    Replace the ParseSolution method in MainWindow.xaml.cs with the following:

    using Microsoft.Build.Construction;
    private void ParseSolution()
    {
        string solutionPath = @"path\to\your\solution.sln";
        var solution = SolutionFile.Parse(solutionPath);
        foreach (var project in solution.ProjectsInOrder)
        {
            OutputTextBox.Text += project.AbsolutePath + "\n";
        }
    }
    

    This should correctly parse the solution file and list the projects within it.

    Make these changes and see if the issue is resolved.

    0 comments No comments