dotnet / roslyn

The Roslyn .NET compiler provides C# and Visual Basic languages with rich code analysis APIs.
https://docs.microsoft.com/dotnet/csharp/roslyn-sdk/
MIT License
18.57k stars 3.96k forks source link

MSBuildWorkspace.OpenProjectAsync() does not load anything #73327

Open gamadori-osm opened 2 weeks ago

gamadori-osm commented 2 weeks ago

Version Used: VS 17.9.6 Compiler version 4.9.0-3.24121.1 (a98c90d5) .NET 8 C#12

Steps to Reproduce:

  1. Create a new project with the template VisualStudio.Extensibility Extension without VSSDK Compatibility
  2. In the Command1.cs file inside the ExecuteCommandAsync method try to open a project/solution, here's a sample
    public override async Task ExecuteCommandAsync(IClientContext context, CancellationToken cancellationToken)
    {
    try
    {
        // I've tried several versions, the behaviour does not change
        MSBuildLocator.RegisterDefaults();
        using var workspace = MSBuildWorkspace.Create();
        // Does not open the project neither returns some error
        var project = await workspace.OpenProjectAsync("{path to some project}");
    }
    catch (Exception ex)
    {
        Debug.WriteLine(ex.Message);
    }
    }

Expected Behavior: open the project or throw some error. I don't know if what I am trying to do is possible or if it is the right way to do it but I would have expected at least an error of some kind.

Actual Behavior: the process does not go on, it seems to go on an endless wait