Version Used:
Roslyn v2.6.0
VS2017 15.5.6
Steps to Reproduce:
I have an analyzer for reading the XML Documentation and analyzing it. We have this analyzer added as an analyzer reference to a project where we have methods documented with XML Documentation.
E.g.
/// <summary>
/// API:Yes
/// </summary>
public void Method()
{
}
I use below code snippet to read XML Documentation.
var leadingTrivia = methodDeclarationSyntaxNode.GetLeadingTrivia();
var singleLineDocumentation = leadingTrivia.FirstOrDefault(trivia => trivia.Kind() == SyntaxKind.SingleLineDocumentationCommentTrivia);
Analyzer identifies this as proper XML documentation as it uses SingleLineDocumentationCommentTrivia for identifying XML Documentation.
Expected Behavior:
Both VS2017 IDE Code analysis and msbuild compilation which triggers Roslyn analyzers should give same SyntaxTree structure for LeadingTrivia.
Actually, we should get SingleLineDocumentationTrivia as we have XML documentation, not just a comment node.
Actual Behavior:
VS2017 IDE Shows proper SingleLineDocumentationTrivia when we have a proper XML documentation. But msbuild triggered analyzer instance shows different syntax tree where only SingleLineCommentTrivia observed.
Please let me know your comment on this difference in behavior which is affecting one of our XML Documentation related analyzer.
Thanks
Basanth
XML documentation output must be enabled, or the compiler will just treat them like normal comments. See #10003, #2773.
We created StyleCop Analyzers rule SA0001 for this scenario. It explains the requirement and provides workarounds for problems people may experience when turning this feature on.
Duplicate of #10003
Most helpful comment
XML documentation output must be enabled, or the compiler will just treat them like normal comments. See #10003, #2773.
We created StyleCop Analyzers rule SA0001 for this scenario. It explains the requirement and provides workarounds for problems people may experience when turning this feature on.