Why does a Roslyn compilation include metadata references or project references but not both?

♀尐吖头ヾ 提交于 2020-01-05 12:59:34

问题


I'm using Roslyn to look at a project that references a number of System assemblies, like this:

var workspace = MSBuildWorkspace.Create();
_solution = workspace.OpenSolutionAsync(_solutionPath).Result;
var project = _solution.Projects.Single(p => p.Name == "TestProject");

When I look at project.MetadataReferences it has 9 elements and project.ProjectReferences has no elements - all as I'd expect. The Documents property contains one more document than I'd expect, a generated document.

If I add a reference from this project to another, then project.ProjectReferences has one element, as I'd expect, but project.MetadataReferences has no references and hundreds of diagnostic errors due to missing System types. The generated document is not there.

The only change is adding the project reference. Why would all the metadata references disappear?

来源:https://stackoverflow.com/questions/49715898/why-does-a-roslyn-compilation-include-metadata-references-or-project-references

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