Roslyn引发不支持语言"C#" [英] Roslyn throws The language 'C#' is not supported

查看:88
本文介绍了Roslyn引发不支持语言"C#"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个类库项目,并进行了一些处理,还使用了Roslyn生成代码.

I have created a class library project and did some processing and also used Roslyn to generate code.

我将WPF GUI应用程序中的库用作参考.

I use the library in a WPF GUI application as a reference.

这些是NuGet软件包:

These are the NuGet packages:

Build没有显示错误,但是当我使用以下代码时:

Build shows no error, however when I use the following code:

private static void GetGenerator()
{
  workspace = new AdhocWorkspace();
  generator = SyntaxGenerator.GetGenerator(workspace, LanguageNames.CSharp);
}

我得到一个例外:

不支持语言'C#'."

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

   at: Microsoft.CodeAnalysis.Host.HostWorkspaceServices.GetLanguageServices(String languageName)
   at: Microsoft.CodeAnalysis.Host.Mef.MefWorkspaceServices.GetLanguageServices(String languageName)
   at: Microsoft.CodeAnalysis.Editing.SyntaxGenerator.GetGenerator(Workspace workspace, String language)

根据,我必须在本地复制CodeAnalysis文件并添加必要的引用.它们在那里,但发生错误.

According to this and this, I have to copy the CodeAnalysis files locally and add the necessary references. They are there, yet the error occurs.

这仍然是去年未修复的错误吗?

Is this still a bug that wasn't fixed in the last year?

我还应该做什么?

推荐答案

您必须将 Microsoft.CodeAnalysis 程序包添加到两个类库项目中引用项目.

这篇关于Roslyn引发不支持语言"C#"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆