Roslyn - CSharpCompilation 到 CSharpCompilation 参考

Roslyn - CSharpCompilation to CSharpCompilation reference

我想将现有的 CSharpCompilation 对象包含到新的 CSharpCompilation 对象中。类似于 c# 中的项目到项目引用。 我目前的解决方案是在新编译中包含第一次编译的语法树,但是当我需要比较两个编译中的符号时(它们不相同),这会产生问题。 MetadataReference.CreateFrom...(),不包含编译重载。 这有可能吗?

我相信您正在寻找 the CompilationReference type, which can be created by calling CSharpCompilation.ToMetadataReference()

您需要将两个 Compilations' Projects 放在同一个 Solution 中,然后添加一个 ProjectReference.