Roslyn throws The language 'C#' is not supported

前端 未结 2 1357
抹茶落季
抹茶落季 2021-01-07 20:25

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

I use the library in a WPF GUI application as a refere

相关标签:
2条回答
  • 2021-01-07 20:44

    Most likely it's because you don't reference Microsoft.CodeAnalysis.CSharp.Workspaces in your code, i.e. you never use a type or method in this dll, so MSBuild thinks it's not needed (see e.g. this question).

    So what you could do is e.g. add the following line somewhere in your class library project:

    var _ = typeof(Microsoft.CodeAnalysis.CSharp.Formatting.CSharpFormattingOptions);
    

    Then MSBuild should copy Microsoft.CodeAnalysis.CSharp.Workspaces.dll over and everything should be fine. No need to reference the NuGet packages from all the other projects.

    0 讨论(0)
  • 2021-01-07 20:44

    You have to add the Microsoft.CodeAnalysis package to both the class library project AND the referencing project as well.

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