Buildalyzer icon indicating copy to clipboard operation
Buildalyzer copied to clipboard

Xml documentation is missing for imported symbols in Roslyn Projects

Open vladimirKa002 opened this issue 1 year ago • 2 comments

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?

vladimirKa002 avatar Jan 31 '24 21:01 vladimirKa002

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

Corniel avatar Feb 05 '24 07:02 Corniel

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.

vladimirKa002 avatar Feb 05 '24 08:02 vladimirKa002

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.

phmonte avatar Feb 18 '24 23:02 phmonte