phmonte / Buildalyzer

A utility to perform design-time builds of .NET projects without having to think too hard about it.
MIT License
589 stars 92 forks source link

Xml documentation is missing for imported symbols in Roslyn Projects #246

Closed vladimirKa002 closed 4 months ago

vladimirKa002 commented 5 months ago

Hello. I need to extract Xml documentation from all ISymbols. For this, I run this code to create a Roslyn Project and start its analysis:

AnalyzerManager manager = new AnalyzerManager();
IProjectAnalyzer analyzer = manager.GetProject(projectPath);
AdhocWorkspace workspace = new AdhocWorkspace();
Project project = analyzer.AddToWorkspace(workspace);

Compilation compilation = project.GetCompilationAsync().Result;

// ... For each document in project.Documents
var syntaxTree = document.GetSyntaxTreeAsync().Result;
var semanticModel = compilation.GetSemanticModel(syntaxTree, true);

// ... Get some symbol from syntaxtree using semanticmodel and extract Xml
var xml = symbol.GetDocumentationCommentXml(expandIncludes: true);

I can normally obtain Xml documentation for symbols declared inside the project.

However, no documentation is available for symbols loaded from imported packages. For example, if my analyser meets List symbol, it does not have Xml comment despite it is imported properly in analysed code.

Could you please advise do I miss anything in my code or maybe my Project loading stage is wrong?

Corniel commented 5 months ago

So, If I understand you correctly, you receive the XML-comments from your own code, but not from referenced code?

vladimirKa002 commented 5 months ago

I am able to receive Xml-comments from the project's code itself. For example, if I run analysis of some project, the documentation of its classes and methods will be loaded normally. However, this project also uses some classes from referenced packages, for example, List class - its Xml documentation is missing.

phmonte commented 4 months ago

Hello @vladimirKa002, I believe I understand what you mean, I was curious and did some local tests, I really didn't find a way that works. Looking at swashbuckle it seems to me (I'm not sure) that it works because it reads the XML file from the repository, it would be an alternative to a "controlled" external reference where you have access to the XML, but you would have to code something to do this. I found this discussion that seems to be the same topic we are talking about here.