Share via

Solution Parser not working in .Net8

Sanjay Kumar Jha 156 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

Developer technologies | Windows Forms
Developer technologies | Windows Presentation Foundation
Windows for business | Windows Client for IT Pros | User experience | Other
Developer technologies | C#
Developer technologies | 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.


1 answer

Sort by: Most helpful
  1. can kucukgultekin 330 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

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.