Skip to content

Conversation

@j-d-ha
Copy link
Collaborator

@j-d-ha j-d-ha commented Dec 21, 2025

🚀 Pull Request

📋 Summary

This PR adds comprehensive MSBuild property support to the source generator, allowing developers to control which features get generated through project configuration. The implementation includes:

  • Include/Exclude Properties: Control feature generation via SourceGeneratorToolsInclude and SourceGeneratorToolsExclude MSBuild properties
  • Public Modifier Support: Optional SourceGeneratorToolsUsePublicModifier property to generate public APIs instead of internal
  • Enhanced Feature Set: Added HashCode as a standalone generatable feature alongside EquatableArray
  • Comprehensive Testing: Added snapshot-based unit tests using Verify to ensure generator output correctness
  • Improved Developer Experience: Added .props file for automatic property visibility and launch settings for debugging

Key changes:

  • New CompilationOptions struct to encapsulate generator configuration
  • Logic to handle include/exclude semantics (include takes precedence, exclude filters from all features)
  • Refactored GeneratorConstants.Features from GeneratableFeature struct to simpler Dictionary<string, string[]>
  • Added comprehensive snapshot tests covering default, include, and exclude scenarios
  • Updated example project to demonstrate MSBuild property usage

✅ Checklist

  • My changes build cleanly
  • I've added/updated relevant tests (11 commits worth of test infrastructure and snapshot tests)
  • I've added/updated documentation or README
  • I've followed the coding style for this project
  • I've tested the changes locally (verified via BasicExample project)

🧪 Related Issues or PRs

Enhances the source generator with user-requested configurability for feature generation.


💬 Notes for Reviewers

Testing approach: This PR uses Verify.SourceGenerators for snapshot testing, which provides reliable verification of generated source code across different scenarios.

MSBuild property logic:

  1. If SourceGeneratorToolsInclude is set, only those features are generated (exclude is ignored)
  2. If SourceGeneratorToolsExclude is set, all features except excluded ones are generated
  3. Default behavior (no properties): all features are generated

Breaking changes: None - all changes are additive and maintain backward compatibility.

Performance: Generator now uses incremental generation pipeline with proper caching of MSBuild properties.

- Moved `HashCodeTests.cs` to the `Utilities` folder.
- Adjusted path of `EquatableArrayTests` to `Types/EquatableArray/`.
…r tools

- Added a new test project, `LayeredCraft.SourceGeneratorTools.Generator.UnitTests`.
- Configured multi-targeting for `net8.0`, `net9.0`, and `net10.0`.
- Implemented `GeneratorTestHelpers` for verifying source generator outputs.
- Added necessary package references (e.g., `Verify.SourceGenerators`, `xunit.v3`).
- Updated solution file to include the new test project.
- Adjusted `Directory.Packages.props` with updated dependency versions.
…t file

- Removed the `RootNamespace` property from the test project file.
- Added `ModuleInitializer` to initialize `VerifySourceGenerators` for tests.
- Added snapshot tests to verify generator outputs for `EquatableArray` and `HashCode`.
- Updated `GeneratorTestHelpers` to support customizable analyzer options.
- Added `Snapshots` folder to the test project file for organizing generated snapshots.
- Introduced `EquatableArrayExtensions.g.cs` and `HashCode.g.cs` as test outputs.
- Adjusted `.gitignore` to include rules for `*.received.*` snapshot files.
…utilities

- Added `AwesomeAssertions`, `Microsoft.CodeAnalysis`, `Microsoft.CodeAnalysis.CSharp`,
  and `Microsoft.CodeAnalysis.Diagnostics` to `GeneratorTestHelpers`.
- Added `JetBrains.Annotations` to `SourceGeneratorToolsGeneratorTests`.
…nfiguration

- Introduced `TestAnalyzerConfigOptionsProvider` for unit tests to mock MSBuild properties.
- Added `CompilationOptions` struct to support `Include`, `Exclude`, and `UsePublicModifier` properties.
- Updated `SourceGeneratorToolsGenerator` for dynamic generation based on MSBuild properties.
- Introduced `LayeredCraft.SourceGeneratorTools.Generator.props` file to define properties.
- Modified feature generation logic with inclusion/exclusion handling based on MSBuild configuration.
- Updated `GeneratorConstants` to define `AllFeatures` and simplify feature management.
- Replaced `EmitCompilerVisibleProperty` with `<CompilerVisibleProperty>` for streamlined property definition.
- Updated test cases to include verification for `SourceGeneratorToolsUsePublicModifier` behavior.
- Refined generator logic to handle properties dynamically and added `static` where applicable for optimization.
- Included launch settings for debugging Roslyn components with an example project.
- Updated feature generation logic to avoid null checks and ensure valid default behavior.
- Enhanced test project to reflect new property-driven source generation and snapshot tests.
- Included distinct file reference handling for better generator accuracy.
…`HashCode`, and related extensions

- Added snapshot tests to verify source generator outputs for `EquatableArray` and `HashCode`.
- Introduced `EquatableArray.g.cs`, `EquatableArrayExtensions.g.cs`, and `HashCode.g.cs` as test outputs.
- Updated `GeneratorTestHelpers` to support customizable analyzer options.
- Refined test project organization by adding output snapshots under the `Snapshots` folder.
- Adjusted `.gitignore` to handle `*.received.*` snapshot files.
…perty behavior

- Added unit tests for `SourceGeneratorToolsInclude` and `SourceGeneratorToolsExclude` properties.
- Verified that `Include` supersedes `Exclude` behavior via snapshot tests.
- Introduced corresponding snapshot files to validate generator outputs.
- Updated test organization with new cases to improve coverage.
- Deleted `GeneratableFeature` as it is no longer used in the generator codebase.
- Simplified the generator by eliminating unnecessary structures to maintain cleaner code.
- Added a detailed pull request template to guide contributors with summary, checklist, and notes.
- Revised structure to include sections for related issues or PRs and specific reviewer notes.
- Enhanced formatting for better readability in the markdown file.
- Deleted the `<EmitCompilerVisibleProperty>` group as it is no longer required.
- Simplified the build configuration to maintain clarity and remove unused properties in MSBuild.
@j-d-ha j-d-ha merged commit 7a060e3 into main Dec 21, 2025
1 check passed
@j-d-ha j-d-ha deleted the feature/add-generation-options branch December 21, 2025 15:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants