Using an AdHocWorkspace results in “The language 'C#' is not supported.”

被刻印的时光 ゝ 提交于 2019-12-07 05:39:00

问题


Using the RC2 of Microsoft.CodeAnalysis.CSharp.Workspaces in VS2015, this code throws an exception:

var tree = CSharpSyntaxTree.ParseText(...);
var workspace = new AdhocWorkspace();
var newRoot = Simplifier.Expand(tree.GetRoot(),
    compilation.GetSemanticModel(tree, false),
    workspace,
    n => true,
    true,
    CancellationToken.None);

The exception message is "The language 'C#' is not supported."

What am I missing to make this work?


回答1:


You need to add a reference to the C# Workspaces NuGet package.

This will copy the C# DLLs to your output, and let Roslyn's MEF scanner see the language services.



来源:https://stackoverflow.com/questions/30601934/using-an-adhocworkspace-results-in-the-language-c-is-not-supported

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!