Fix XML documentation generation to appear in IDE tooltips + recommend markdown
Co-authored-by: omegaleo <5655201+omegaleo@users.noreply.github.com>
This commit is contained in:
@@ -1,5 +1,27 @@
|
|||||||
# Documentation Attribute IDE Tooltip Example
|
# Documentation Attribute IDE Tooltip Example
|
||||||
|
|
||||||
|
## Recommended: Use Markdown for Code Examples
|
||||||
|
|
||||||
|
For the best IDE experience, we **strongly recommend using markdown code fences** in your `codeExample` parameter:
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
[Documentation(
|
||||||
|
"MyMethod",
|
||||||
|
"Does something cool",
|
||||||
|
new[] { "param: Description" },
|
||||||
|
@"```csharp
|
||||||
|
// Use markdown code fences like this!
|
||||||
|
MyMethod(""example"");
|
||||||
|
```"
|
||||||
|
)]
|
||||||
|
```
|
||||||
|
|
||||||
|
This provides:
|
||||||
|
- ✅ Proper syntax highlighting in IDEs
|
||||||
|
- ✅ Better formatting in IntelliSense tooltips
|
||||||
|
- ✅ Consistent appearance across Visual Studio, Rider, and VS Code
|
||||||
|
- ✅ Markdown rendering in documentation generators
|
||||||
|
|
||||||
## Before (Without XML Doc Generator)
|
## Before (Without XML Doc Generator)
|
||||||
|
|
||||||
When using the `DocumentationAttribute` without the XML Doc Generator, IDEs would not show the documentation:
|
When using the `DocumentationAttribute` without the XML Doc Generator, IDEs would not show the documentation:
|
||||||
|
|||||||
@@ -22,12 +22,37 @@ If you want to use the XmlDocGenerator standalone:
|
|||||||
dotnet add package OmegaLeo.HelperLib.XmlDocGenerator
|
dotnet add package OmegaLeo.HelperLib.XmlDocGenerator
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Usage Best Practices
|
||||||
|
|
||||||
|
### ✨ Recommended: Use Markdown in Code Examples
|
||||||
|
|
||||||
|
For the best IDE experience, **use markdown code fences** in your `codeExample` parameter:
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
[Documentation(
|
||||||
|
"MyMethod",
|
||||||
|
"Does something cool",
|
||||||
|
new[] { "param: Description" },
|
||||||
|
@"```csharp
|
||||||
|
// Markdown code fence provides syntax highlighting!
|
||||||
|
MyMethod(""example"");
|
||||||
|
```"
|
||||||
|
)]
|
||||||
|
public void MyMethod(string param) { }
|
||||||
|
```
|
||||||
|
|
||||||
|
**Benefits:**
|
||||||
|
- ✅ Proper syntax highlighting in Visual Studio, Rider, and VS Code
|
||||||
|
- ✅ Better formatting in IntelliSense tooltips
|
||||||
|
- ✅ Professional appearance
|
||||||
|
- ✅ Works with documentation generators
|
||||||
|
|
||||||
## How It Works
|
## How It Works
|
||||||
|
|
||||||
1. **MSBuild Integration**: The package includes MSBuild targets that are automatically imported
|
1. **MSBuild Integration**: The package includes MSBuild targets that are automatically imported
|
||||||
2. **Build-Time Generation**: Runs after CoreCompile to analyze your compiled assembly
|
2. **Build-Time Generation**: Runs after Build to augment your final XML documentation
|
||||||
3. **Attribute Reading**: Uses reflection to read DocumentationAttribute instances
|
3. **Attribute Reading**: Uses reflection to read DocumentationAttribute instances
|
||||||
4. **XML Generation**: Creates/augments XML documentation files
|
4. **XML Generation**: Creates/augments XML documentation files in your output directory
|
||||||
5. **IntelliSense Ready**: IDEs automatically pick up the generated XML
|
5. **IntelliSense Ready**: IDEs automatically pick up the generated XML
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
|||||||
@@ -2,14 +2,15 @@
|
|||||||
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
|
|
||||||
<Target Name="GenerateXmlDocFromDocumentationAttribute"
|
<Target Name="GenerateXmlDocFromDocumentationAttribute"
|
||||||
AfterTargets="CoreCompile"
|
AfterTargets="Build"
|
||||||
Condition="'$(GenerateXmlDocFromDocumentationAttribute)' == 'true' And '$(TargetFramework)' != ''">
|
Condition="'$(GenerateXmlDocFromDocumentationAttribute)' == 'true' And '$(TargetFramework)' != ''">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<!-- Path to the XmlDocGenerator tool in the NuGet package -->
|
<!-- Path to the XmlDocGenerator tool in the NuGet package -->
|
||||||
<XmlDocGenToolPath>$(MSBuildThisFileDirectory)..\tools\net8.0\OmegaLeo.HelperLib.XmlDocGenerator.dll</XmlDocGenToolPath>
|
<XmlDocGenToolPath>$(MSBuildThisFileDirectory)..\tools\net8.0\OmegaLeo.HelperLib.XmlDocGenerator.dll</XmlDocGenToolPath>
|
||||||
<TargetAssemblyPath>$(IntermediateOutputPath)$(TargetFileName)</TargetAssemblyPath>
|
<!-- Target the final output assembly and XML, not intermediate -->
|
||||||
<TargetXmlDocPath>$(IntermediateOutputPath)$(TargetName).xml</TargetXmlDocPath>
|
<TargetAssemblyPath>$(TargetDir)$(TargetFileName)</TargetAssemblyPath>
|
||||||
|
<TargetXmlDocPath>$(TargetDir)$(TargetName).xml</TargetXmlDocPath>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<Message Text="[DocumentationAttribute] Generating XML documentation from DocumentationAttribute for $(TargetName)"
|
<Message Text="[DocumentationAttribute] Generating XML documentation from DocumentationAttribute for $(TargetName)"
|
||||||
|
|||||||
@@ -12,14 +12,15 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<Target Name="GenerateXmlDocFromDocumentationAttribute_Local"
|
<Target Name="GenerateXmlDocFromDocumentationAttribute_Local"
|
||||||
AfterTargets="CoreCompile"
|
AfterTargets="Build"
|
||||||
Condition="'$(GenerateXmlDocFromDocumentationAttribute)' == 'true' And '$(TargetFramework)' != ''">
|
Condition="'$(GenerateXmlDocFromDocumentationAttribute)' == 'true' And '$(TargetFramework)' != ''">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<!-- For local development, use the built tool from the sibling project -->
|
<!-- For local development, use the built tool from the sibling project -->
|
||||||
<XmlDocGenToolPath_Local>$(MSBuildThisFileDirectory)OmegaLeo.HelperLib.XmlDocGenerator/bin/$(Configuration)/net8.0/OmegaLeo.HelperLib.XmlDocGenerator.dll</XmlDocGenToolPath_Local>
|
<XmlDocGenToolPath_Local>$(MSBuildThisFileDirectory)OmegaLeo.HelperLib.XmlDocGenerator/bin/$(Configuration)/net8.0/OmegaLeo.HelperLib.XmlDocGenerator.dll</XmlDocGenToolPath_Local>
|
||||||
<TargetAssemblyPath>$(IntermediateOutputPath)$(TargetFileName)</TargetAssemblyPath>
|
<!-- Target the final output assembly and XML, not intermediate -->
|
||||||
<TargetXmlDocPath>$(IntermediateOutputPath)$(TargetName).xml</TargetXmlDocPath>
|
<TargetAssemblyPath>$(TargetDir)$(TargetFileName)</TargetAssemblyPath>
|
||||||
|
<TargetXmlDocPath>$(TargetDir)$(TargetName).xml</TargetXmlDocPath>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<Message Text="[DocumentationAttribute] Generating XML documentation from DocumentationAttribute for $(TargetName)"
|
<Message Text="[DocumentationAttribute] Generating XML documentation from DocumentationAttribute for $(TargetName)"
|
||||||
@@ -30,6 +31,10 @@
|
|||||||
Importance="high"
|
Importance="high"
|
||||||
Condition="!Exists('$(XmlDocGenToolPath_Local)')" />
|
Condition="!Exists('$(XmlDocGenToolPath_Local)')" />
|
||||||
|
|
||||||
|
<Message Text="[DocumentationAttribute] Target assembly not found at: $(TargetAssemblyPath)"
|
||||||
|
Importance="high"
|
||||||
|
Condition="!Exists('$(TargetAssemblyPath)')" />
|
||||||
|
|
||||||
<!-- Run the XmlDocGenerator tool -->
|
<!-- Run the XmlDocGenerator tool -->
|
||||||
<Exec Command="dotnet "$(XmlDocGenToolPath_Local)" "$(TargetAssemblyPath)" "$(TargetXmlDocPath)""
|
<Exec Command="dotnet "$(XmlDocGenToolPath_Local)" "$(TargetAssemblyPath)" "$(TargetXmlDocPath)""
|
||||||
Condition="Exists('$(XmlDocGenToolPath_Local)') And Exists('$(TargetAssemblyPath)')"
|
Condition="Exists('$(XmlDocGenToolPath_Local)') And Exists('$(TargetAssemblyPath)')"
|
||||||
|
|||||||
Reference in New Issue
Block a user