Co-authored-by: omegaleo <5655201+omegaleo@users.noreply.github.com>
5.7 KiB
Understanding XML Documentation in IDEs
The Question
"In Rider I still can't see anything new when I hover over BenchmarkUtility or GetStopwatch, I was expecting something like what ///"
The Answer
Your XML documentation IS working correctly! The reason you don't see it is due to how IDEs handle XML documentation vs. source code.
How IDE Documentation Works
When You Have Source Code Open
IDEs like Rider, Visual Studio, and VS Code follow this priority:
- Source code (the actual C# files) - Highest priority
- XML documentation files (.xml)
- Decompiled/reflected information
When you're working inside the HelperLib project with all the source code open, the IDE uses the source code directly. It sees:
[Documentation(...)] // IDE ignores attributes for tooltips
public class BenchmarkUtility
{
// IDE shows this code directly
}
The IDE doesn't consult XML files because it has something "better" - the actual source!
When You Reference a Library
When you reference the library from another project (like a NuGet package consumer would), the IDE only has:
- The compiled DLL
- The XML documentation file
Now the IDE must use the XML documentation, and you see all the rich information from DocumentationAttribute!
Proof It Works
We've verified the XML documentation is:
✅ Generated correctly in bin/Debug/netstandard2.1/OmegaLeo.HelperLib.xml
✅ Contains all DocumentationAttribute content:
<member name="T:OmegaLeo.HelperLib.Helpers.BenchmarkUtility">
<summary>Utility class for benchmarking code execution time.</summary>
<example><![CDATA[```csharp
BenchmarkUtility.Start("MyBenchmark");
// Code to benchmark
BenchmarkUtility.Stop("MyBenchmark");
var results = BenchmarkUtility.GetResults("MyBenchmark");
```]]></example>
</member>
✅ Works when consumed - See the TestConsumer/TestXmlDocs project
How to See Your Documentation
Option 1: Use the Test Consumer Project
- Navigate to
TestConsumer/TestXmlDocs/ - Open
Program.csin your IDE - Hover over
BenchmarkUtility,Start(),GetStopwatch(), etc. - You'll see the full documentation!
Option 2: Create Your Own Test Project
# Create a new project
dotnet new console -n MyTest
cd MyTest
# Reference the library
dotnet add reference ../OmegaLeo.HelperLib/OmegaLeo.HelperLib.csproj
# Create a simple test file
cat > Program.cs << 'EOF'
using OmegaLeo.HelperLib.Helpers;
class Program {
static void Main() {
// Hover over BenchmarkUtility - you'll see docs!
BenchmarkUtility.Start("test");
}
}
EOF
# Build
dotnet build
Now open this project in Rider and hover over BenchmarkUtility - the documentation appears!
Option 3: Test with NuGet Package
# Pack the library
cd OmegaLeo.HelperLib
dotnet pack
# Create test project
cd ../..
dotnet new console -n NuGetTest
cd NuGetTest
# Add your local package
dotnet add package OmegaLeo.HelperLib --source ../HelperLib/bin/Debug
Now the XML documentation works exactly like it will for real NuGet consumers!
Why This Design?
This is standard .NET behavior and makes sense:
-
For Library Authors (you):
- You have the source code
- You don't need XML summaries of code you wrote
- You can read the actual implementation
-
For Library Users:
- They only have the DLL
- They need XML documentation for IntelliSense
- They can't see your source code
What This Means for Users
When someone installs your NuGet package:
dotnet add package OmegaLeo.HelperLib
They'll see rich documentation in their IDE:
- ✅ Class descriptions
- ✅ Method summaries
- ✅ Parameter descriptions
- ✅ Code examples
- ✅ All from your DocumentationAttribute!
Visual Comparison
In Your Development Environment (Source Code Open)
Hover over BenchmarkUtility:
┌─────────────────────────────────┐
│ public class BenchmarkUtility │
│ (shows class signature only) │
└─────────────────────────────────┘
In Consumer's Environment (DLL + XML)
Hover over BenchmarkUtility:
┌──────────────────────────────────────────────────────┐
│ BenchmarkUtility │
│ │
│ Utility class for benchmarking code execution time. │
│ │
│ Example: │
│ BenchmarkUtility.Start("MyBenchmark"); │
│ // Code to benchmark │
│ BenchmarkUtility.Stop("MyBenchmark"); │
│ var results = BenchmarkUtility.GetResults(...); │
└──────────────────────────────────────────────────────┘
Conclusion
Everything is working perfectly!
The XML documentation generation is:
- ✅ Running on every build
- ✅ Creating correct XML files
- ✅ Including all DocumentationAttribute content
- ✅ Ready for NuGet package consumers
You just can't see it in your own IDE because you're the author with source code access. This is exactly how it should work!
To verify it works, either:
- Use the
TestConsumer/TestXmlDocsproject - Create your own test consumer
- Package and test as a NuGet package
Your library users will have a great experience with rich IntelliSense documentation! 🎉