|
| 1 | +# Project Guidelines for Claude Code |
| 2 | + |
| 3 | +## Project Information |
| 4 | + |
| 5 | +- **Repository**: ANcpLua/CreatePdf.NET |
| 6 | +- **Package ID**: CreatePdf.NET |
| 7 | +- **Current Version**: Check `CreatePdf.NET/CreatePdf.NET.csproj` |
| 8 | +- **Project Path**: `/Users/ancplua/CreatePdf.NET` |
| 9 | +- **Main Branch**: main |
| 10 | +- **Multi-Targeting**: .NET 10.0, 9.0, 8.0 |
| 11 | + |
| 12 | +## Versioning & Release Strategy |
| 13 | + |
| 14 | +### Semantic Versioning (MAJOR.MINOR.PATCH) |
| 15 | + |
| 16 | +- **MAJOR** (x.0.0) - Breaking API changes, major architectural changes |
| 17 | +- **MINOR** (3.x.0) - New features, non-breaking additions |
| 18 | +- **PATCH** (3.0.x) - Bug fixes, minor tweaks, icon updates, documentation |
| 19 | + |
| 20 | +### Release Rules |
| 21 | + |
| 22 | +#### Major Versions (x.0.0) |
| 23 | +- ✅ Bump version in `.csproj` |
| 24 | +- ✅ Commit and push to GitHub |
| 25 | +- ✅ Create GitHub Release with detailed release notes |
| 26 | +- ✅ Publish to NuGet |
| 27 | +- 📝 Document breaking changes and migration guide |
| 28 | + |
| 29 | +#### Minor Versions (3.x.0) |
| 30 | +- ✅ Bump version in `.csproj` |
| 31 | +- ✅ Commit and push to GitHub |
| 32 | +- ✅ Create GitHub Release with feature descriptions |
| 33 | +- ✅ Publish to NuGet |
| 34 | +- 📝 Document new features and usage examples |
| 35 | + |
| 36 | +#### Patch Versions (3.0.x) |
| 37 | +- ✅ Bump version in `.csproj` |
| 38 | +- ✅ Commit and push to GitHub |
| 39 | +- ❌ NO GitHub Release needed |
| 40 | +- ✅ Publish to NuGet |
| 41 | +- 💡 Optional: Create git tag for tracking |
| 42 | +- 💡 Keep commit messages clear (they're the documentation) |
| 43 | + |
| 44 | +### Quick Reference |
| 45 | + |
| 46 | +| Change Type | Example | GitHub Release? | NuGet Publish? | |
| 47 | +|-------------|---------|-----------------|----------------| |
| 48 | +| Breaking change | API removal | ✅ YES | ✅ YES | |
| 49 | +| New feature | Add bitmap support | ✅ YES | ✅ YES | |
| 50 | +| Bug fix | Fix text rendering | ❌ NO | ✅ YES | |
| 51 | +| Icon update | Adjust positioning | ❌ NO | ✅ YES | |
| 52 | +| Documentation | Update README | ❌ NO | ❌ NO* | |
| 53 | + |
| 54 | +*Documentation-only changes don't need version bumps |
| 55 | + |
| 56 | +## Current Automation |
| 57 | + |
| 58 | +### GitHub Actions Workflows |
| 59 | + |
| 60 | +#### `nuget-publish.yml` |
| 61 | +- Triggers: |
| 62 | + - GitHub Release published |
| 63 | + - Manual workflow dispatch |
| 64 | +- Runs: |
| 65 | + 1. Auto-center/optimize icon (ImageMagick: trim, resize 512x512, transparent background) |
| 66 | + 2. Build, test, pack, publish to NuGet |
| 67 | +- Authentication: NuGet Trusted Publishing (OIDC) - no API key needed |
| 68 | + |
| 69 | +### Publishing Workflows |
| 70 | + |
| 71 | +#### Option 1: Automated Publishing (Recommended for Major/Minor) |
| 72 | + |
| 73 | +**For major and minor versions**, create a GitHub Release: |
| 74 | + |
| 75 | +1. Go to https://github.com/ANcpLua/CreatePdf.NET/releases/new |
| 76 | +2. Create new tag: `v3.x.0` |
| 77 | +3. Generate release notes |
| 78 | +4. Publish release |
| 79 | +5. GitHub Actions will automatically build, test, optimize icon, and publish to NuGet via Trusted Publishing |
| 80 | + |
| 81 | +#### Option 2: Manual Workflow Dispatch |
| 82 | + |
| 83 | +Trigger the workflow manually from GitHub Actions UI for any version without creating a release. |
| 84 | + |
| 85 | +#### Option 3: Manual Publishing (Current for Patches) |
| 86 | + |
| 87 | +For patch versions, we manually publish: |
| 88 | + |
| 89 | +```bash |
| 90 | +# Working directory: /Users/ancplua/CreatePdf.NET |
| 91 | + |
| 92 | +# 1. Bump version in .csproj |
| 93 | +# Edit: CreatePdf.NET/CreatePdf.NET.csproj |
| 94 | +# Change: <Version>3.0.x</Version> |
| 95 | + |
| 96 | +# 2. Commit and push |
| 97 | +git add CreatePdf.NET/CreatePdf.NET.csproj icon.png |
| 98 | +git commit -m "v3.0.x - Description" |
| 99 | +git push |
| 100 | + |
| 101 | +# 3. Build package |
| 102 | +dotnet pack CreatePdf.NET/CreatePdf.NET.csproj --configuration Release |
| 103 | + |
| 104 | +# 4. Publish to NuGet (using Trusted Publishing or API key) |
| 105 | +# With Trusted Publishing (if configured): |
| 106 | +# - Use GitHub Actions workflow dispatch |
| 107 | +# OR with API key: |
| 108 | +dotnet nuget push CreatePdf.NET/bin/Release/CreatePdf.NET.3.0.x.nupkg \ |
| 109 | + --api-key $NUGET_API_KEY \ |
| 110 | + --source https://api.nuget.org/v3/index.json \ |
| 111 | + --skip-duplicate |
| 112 | +``` |
| 113 | + |
| 114 | +**Note**: Trusted Publishing is configured, so API keys are optional. Prefer using GitHub Actions workflows. |
| 115 | + |
| 116 | +## Package Metadata |
| 117 | + |
| 118 | +### Icon Requirements |
| 119 | +- Size: 512x512 PNG (scales down to 128x128, 64x64) |
| 120 | +- Location: `icon.png` in repository root |
| 121 | +- Referenced in `.csproj`: `<PackageIcon>icon.png</PackageIcon>` |
| 122 | +- **Auto-optimization**: GitHub Actions workflow automatically trims, resizes, and centers icon before packing |
| 123 | +- Note: NuGet may take 5-10 minutes to update icon after publish |
| 124 | + |
| 125 | +### Tags for Discoverability |
| 126 | +Current tags ensure package appears in searches for: |
| 127 | +- PDF creation, generation, document generation |
| 128 | +- .NET 10, .NET 9, .NET 8 |
| 129 | +- Text rendering, bitmap graphics, OCR |
| 130 | +- Reports, invoices, receipts, labels |
| 131 | + |
| 132 | +## Testing Requirements |
| 133 | + |
| 134 | +All tests must pass before publishing: |
| 135 | +- Unit tests: Core PDF generation, text rendering, bitmap handling |
| 136 | +- Integration tests: OCR functionality with Tesseract |
| 137 | +- 100% code coverage target |
| 138 | +- Tests run on .NET 10, 9, and 8 |
| 139 | + |
| 140 | +### Multi-Targeting Notes |
| 141 | +- Project targets net10.0, net9.0, net8.0 |
| 142 | +- Tests ensure compatibility across all frameworks |
| 143 | +- Use conditional compilation when needed (`#if NET10_0_OR_GREATER`) |
| 144 | + |
| 145 | +## Commit Message Guidelines |
| 146 | + |
| 147 | +Keep commit messages clear and concise: |
| 148 | + |
| 149 | +```bash |
| 150 | +# Good examples (patches) |
| 151 | +"Fix text alignment in pixel rendering" |
| 152 | +"v3.0.3 - Adjust icon positioning for better NuGet display" |
| 153 | + |
| 154 | +# Good examples (features/majors) |
| 155 | +"v3.0.0 - Add multi-framework support (.NET 8/9/10)" |
| 156 | +"v2.5.0 - Add OCR text extraction with Tesseract" |
| 157 | + |
| 158 | +# Avoid |
| 159 | +"Update code" ❌ |
| 160 | +"Fix stuff" ❌ |
| 161 | +"Various improvements" ❌ |
| 162 | +``` |
| 163 | + |
| 164 | +## Architecture Notes |
| 165 | + |
| 166 | +### PDF Generation |
| 167 | +- **Core API**: Fluent interface for building PDFs (`Pdf.Create()`) |
| 168 | +- **Text Rendering**: Two modes - native PDF text and pixel-based rendering |
| 169 | +- **Bitmap Support**: PNG/JPG image embedding |
| 170 | +- **File I/O**: All operations are async-first |
| 171 | + |
| 172 | +### OCR Integration |
| 173 | +- Optional Tesseract integration for text extraction |
| 174 | +- External dependency (tesseract binary) |
| 175 | +- Abstracted via `IOcrProvider` interface for testability |
| 176 | + |
| 177 | +### Multi-Framework Support |
| 178 | +- Targets .NET 10.0, 9.0, 8.0 for maximum compatibility |
| 179 | +- Uses C# 14 language features (LangVersion: 14) |
| 180 | +- Nullable reference types enabled |
| 181 | + |
| 182 | +## .NET 10 Best Practices |
| 183 | + |
| 184 | +### Key Language Features (C# 14) |
| 185 | + |
| 186 | +**Field-Backed Properties:** |
| 187 | +```csharp |
| 188 | +public string Message |
| 189 | +{ |
| 190 | + get; |
| 191 | + set => field = value ?? throw new ArgumentNullException(nameof(value)); |
| 192 | +} |
| 193 | +``` |
| 194 | + |
| 195 | +**Implicit Usings:** |
| 196 | +- Project uses `<ImplicitUsings>enable</ImplicitUsings>` |
| 197 | +- Common namespaces automatically imported |
| 198 | + |
| 199 | +**Nullable Reference Types:** |
| 200 | +- Enabled project-wide: `<Nullable>enable</Nullable>` |
| 201 | +- Helps prevent null reference exceptions |
| 202 | + |
| 203 | +### Library-Specific Recommendations |
| 204 | + |
| 205 | +#### SourceLink Configuration (Critical for Debugging) |
| 206 | +Consider adding to `.csproj` for better consumer debugging: |
| 207 | +```xml |
| 208 | +<PropertyGroup> |
| 209 | + <PublishRepositoryUrl>true</PublishRepositoryUrl> |
| 210 | + <EmbedUntrackedSources>true</EmbedUntrackedSources> |
| 211 | +</PropertyGroup> |
| 212 | + |
| 213 | +<ItemGroup> |
| 214 | + <PackageReference Include="Microsoft.SourceLink.GitHub" Version="*" PrivateAssets="All"/> |
| 215 | +</ItemGroup> |
| 216 | +``` |
| 217 | + |
| 218 | +#### Documentation Generation |
| 219 | +- Already enabled: `<GenerateDocumentationFile>true</GenerateDocumentationFile>` |
| 220 | +- XML comments are included in NuGet package |
| 221 | + |
| 222 | +#### Symbol Packages |
| 223 | +- Already configured: `<SymbolPackageFormat>snupkg</SymbolPackageFormat>` |
| 224 | +- Debugging symbols published separately |
| 225 | + |
| 226 | +### Testing Best Practices |
| 227 | + |
| 228 | +**100% Code Coverage:** |
| 229 | +- Project aims for comprehensive test coverage |
| 230 | +- Use Codecov for tracking coverage metrics |
| 231 | +- All public APIs should have tests |
| 232 | + |
| 233 | +**Multi-Framework Testing:** |
| 234 | +- Tests run on all target frameworks |
| 235 | +- Ensures compatibility across .NET versions |
| 236 | + |
| 237 | +**External Dependencies:** |
| 238 | +- OCR tests require Tesseract binary |
| 239 | +- Use abstractions for testability |
| 240 | +- Mock external dependencies in unit tests |
| 241 | + |
| 242 | +## Official API Documentation Links |
| 243 | + |
| 244 | +**Microsoft Learn (Always Current):** |
| 245 | +- [.NET 10 Release Notes](https://learn.microsoft.com/en-us/dotnet/core/whats-new/dotnet-10/overview) |
| 246 | +- [C# 14 What's New](https://learn.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-14) |
| 247 | +- [Multi-Targeting in SDK-Style Projects](https://learn.microsoft.com/en-us/dotnet/standard/frameworks) |
| 248 | +- [NuGet Package Authoring Best Practices](https://learn.microsoft.com/en-us/nuget/create-packages/package-authoring-best-practices) |
| 249 | +- [SourceLink Configuration](https://learn.microsoft.com/en-us/dotnet/standard/library-guidance/sourcelink) |
| 250 | +- [Nullable Reference Types](https://learn.microsoft.com/en-us/dotnet/csharp/nullable-references) |
| 251 | + |
| 252 | +**Last Updated:** November 20, 2025 |
0 commit comments