DocFX Integration Guide
Docs / References / DocFX Integration Guide
Complete guide to building, maintaining, and deploying ZenECS documentation using DocFX.
Overview
ZenECS uses DocFX to generate a unified documentation website that combines:
- API Documentation: Auto-generated from XML comments in C# source code
- Conceptual Documentation: Manual markdown files in
Docs/directory - Samples: Code examples and tutorials
The final output is a static website in Docs_/_site/ that can be deployed to GitHub Pages or any web server.
Architecture
Directory Structure
Repository Root/
├── Docs/ # Manual documentation (source)
│ ├── overview/
│ ├── getting-started/
│ ├── core/
│ └── ...
│
├── Docs_/ # DocFX configuration and build
│ ├── docfx.json # DocFX configuration
│ ├── toc.yml # Table of contents
│ ├── index.md # Landing page
│ └── _site/ # Generated website (output)
│ ├── index.html
│ ├── api/ # API documentation
│ └── docs/ # Manual documentation
│
└── src/ # Source code (XML comments)
├── ZenECS.Core.csproj
└── ZenECS.Adapter.Unity.csproj
Build Process
- Build Projects: Generate XML documentation files
- Extract Metadata: DocFX reads XML comments and code structure
- Process Markdown: Convert markdown files to HTML
- Generate Site: Combine API docs and manual docs into single site
- Output: Static HTML files in
Docs_/_site/
Configuration
docfx.json
Main configuration file located at Docs_/docfx.json:
{
"metadata": [
{
"src": [
{
"src": "../src",
"files": [
"ZenECS.Core.csproj",
"ZenECS.Adapter.Unity.csproj"
]
}
],
"dest": "api",
"filter": "apiFilter.yml"
}
],
"build": {
"content": [
{
"files": ["**/*.{md,yml}"],
"exclude": ["_site/**"]
},
{
"files": ["../README.md"],
"src": "..",
"dest": "."
},
{
"files": ["**/*.md"],
"src": "../Docs",
"dest": "docs"
}
],
"output": "_site"
}
}
Key Settings
- metadata: Source projects for API documentation
- content: Markdown files to include
- output: Generated site location
- filter: API filtering rules (see
apiFilter.yml)
apiFilter.yml
Controls which APIs are included in documentation:
apiRules:
- exclude:
uidRegex: ^ZenECS\.Core\.Internal
type: Namespace
- exclude:
uidRegex: ^ZenECS\.Adapter\.Unity\.Internal
type: Namespace
- include:
uidRegex: ^ZenECS\.Core
type: Namespace
- include:
uidRegex: ^ZenECS\.Adapter\.Unity
type: Namespace
toc.yml
Table of contents structure:
- name: Home
href: index.md
- name: Getting Started
href: ../README.md
- name: Documentation
items:
- name: Overview
href: ../Docs/overview/zenecs-at-a-glance.md
# ... more items
- name: API Reference
href: api/
Building Documentation
Prerequisites
- .NET SDK 8.0+: For building projects
- DocFX: Install with
dotnet tool install -g docfx
Build Steps
Option 1: Using Build Script (Recommended)
Windows:
.\scripts\build-docfx.ps1
Linux/macOS:
./scripts/build-docfx.sh
Option 2: Manual Build
# 1. Build Core project
cd src
dotnet build ZenECS.Core.csproj -c Release /p:GenerateDocumentationFile=true
# 2. Build Adapter Unity project
dotnet build ZenECS.Adapter.Unity.csproj -c Release /p:GenerateDocumentationFile=true
# 3. Run DocFX
cd ..\Docs_
docfx docfx.json
Build Output
Generated files in Docs_/_site/:
index.html- Main landing pageapi/- API documentation (auto-generated)docs/- Manual documentation (fromDocs/)toc.html- Table of contents- Static assets (CSS, JS, images)
Previewing Documentation
Local Preview Server
cd Docs_
docfx serve _site
Then open http://localhost:8080 in your browser.
Direct File Access
Open Docs_/_site/index.html directly in a browser (some features may not work without a server).
Adding New Documentation
Adding Manual Documentation
- Create file in appropriate
Docs/subdirectory - Follow naming convention:
kebab-case.md - Add to toc.yml: Update table of contents
- Rebuild: Run build script
- Preview: Check in browser
Adding API Documentation
- Add XML comments to source code:
/// <summary> /// Creates a new entity. /// </summary> public Entity CreateEntity() { } - Build project: Generate XML files
- Run DocFX: API docs auto-generated
- Verify: Check
Docs_/_site/api/
Troubleshooting
Common Issues
Issue: API Documentation Missing
Cause: XML documentation not generated
Solution:
# Ensure GenerateDocumentationFile is enabled
dotnet build -c Release /p:GenerateDocumentationFile=true
Issue: Links Broken
Cause: Incorrect relative paths
Solution:
- Use relative paths from
Docs/root - Test links after build
- Check
toc.ymlstructure
Issue: Build Fails
Cause: Invalid markdown or configuration
Solution:
- Check
docfx.jsonsyntax - Validate markdown files
- Review build logs
Build Logs
Check build output for errors:
docfx docfx.json --logLevel verbose
Deployment
GitHub Pages
Option 1: Automatic Deployment
GitHub Actions workflow (.github/workflows/docs-deploy.yml):
- Triggers on push to
mainbranch - Builds documentation
- Deploys to
gh-pagesbranch ordocs/directory
Option 2: Manual Deployment
# Build documentation
.\scripts\build-docfx.ps1
# Deploy to docs/ directory
.\scripts\deploy-docs.ps1
# Commit and push
git add docs/
git commit -m "Update documentation"
git push
Other Hosting
The Docs_/_site/ directory contains a complete static website that can be deployed to:
- Netlify: Drag and drop
_sitefolder - Vercel: Point to
_sitedirectory - Azure Static Web Apps: Deploy
_sitefolder - Any web server: Copy
_sitecontents to web root
Maintenance
Keeping Documentation Updated
- Update with code changes: When APIs change, update XML comments
- Review quarterly: Schedule regular documentation reviews
- Test builds: Verify builds work after major changes
- Check links: Validate all links periodically
Versioning
- API docs: Versioned with code releases
- Manual docs: Update as features change
- Changelog: Document significant doc changes
CI/CD Integration
GitHub Actions automatically:
- Builds documentation on code changes
- Validates documentation structure
- Deploys to GitHub Pages (if configured)
Best Practices
Documentation Structure
- Organize logically: Group related topics
- Use consistent naming: Follow kebab-case convention
- Maintain toc.yml: Keep table of contents updated
- Cross-reference: Link related documents
API Documentation
- Complete XML comments: Document all public APIs
- Include examples: Show usage in XML comments
- Link related APIs: Use
<see cref="..."/> - Document exceptions: Use
<exception>tags
Markdown Files
- Follow template: Use standard document structure
- Test locally: Preview before committing
- Validate links: Check all links work
- Keep current: Update with code changes
Resources
Need Help? Check build logs or contact the documentation team.