Roslyn workspace for .NET Core's new .csproj format

前端 未结 1 1686
悲哀的现实
悲哀的现实 2020-12-31 03:57

I\'ve been working on a VS Code extension that uses Roslyn\'s workspace API to load a project, at the moment the extension supports .NET Core\'s old project.json

相关标签:
1条回答
  • 2020-12-31 04:29

    Having spoken with various people it appears that there is no .NET Standard compatible MS Build workspace, this can be seen by this answer below to the following GitHub issue:

    We haven't done the work to make MSBuildWorkspace work properly with the new MSBuild cross-platform. In the meantime, you might look at what omnisharp does to populate it's workspace.

    So it seems that at the time of writing if you want to target the MSBuild workspace in a .NET Standard compliant project then you'll need to build your own custom workspace using Roslyn's workspace API, this is exactly how OmniSharp do it.

    Update (16/10/2017):

    Whilst MSBuildWorkspace does still not support .NET Standard, there is a library called Buildalyzer that works cross-platform and will generate an AdhocWorkspace for you, allowing you to achieve the same goal.

    using Buildalyzer.Workspaces;
    // ...
    
    AnalyzerManager manager = new AnalyzerManager();
    ProjectAnalyzer analyzer = 
    manager.GetProject(@"C:\MyCode\MyProject.csproj");
    AdhocWorkspace workspace = analyzer.GetWorkspace();
    

    The same library will also allow you to reference a solution file too.

    0 讨论(0)
提交回复
热议问题