C#: NuGet dependency workspace for template type attribution#7061
Merged
knutwannheden merged 3 commits intomainfrom Mar 19, 2026
Merged
C#: NuGet dependency workspace for template type attribution#7061knutwannheden merged 3 commits intomainfrom
knutwannheden merged 3 commits intomainfrom
Conversation
Captures now carry an internal `CaptureKind` (Expression, Type, Name) that tells the template engine what syntactic position the placeholder occupies. This allows `BuildTypePreamble` to dispatch on kind and generate appropriate scaffold code for each position. New factory methods `Capture.Type()` and `Capture.Name()` create captures with the correct kind pre-set while preserving compile-time type safety via the generic parameter.
- Thread `dependencies` (IReadOnlyDictionary<string, string>) through CSharpTemplate.Create, CSharpPattern.Create, and TemplateEngine.Parse for future NuGet-based type attribution during scaffold parsing - Include dependencies in the template cache key - Add Capture.Expression() factory with explicit CaptureKind.Expression - Update Of<T> docs to steer toward position-specific factories
…lates When templates or patterns specify NuGet dependencies, the scaffold is now parsed with a SemanticModel backed by resolved package references. This enables Roslyn to attribute types from external packages (e.g., Newtonsoft.Json.JsonConvert) during template parsing. Uses Microsoft.CodeAnalysis.Testing.ReferenceAssemblies for NuGet resolution — no subprocess or temp .csproj needed. Resolved references are cached by dependency set hash.
knutwannheden
added a commit
that referenced
this pull request
Mar 19, 2026
* C#: Add CaptureKind to template captures for position-aware scaffolding Captures now carry an internal `CaptureKind` (Expression, Type, Name) that tells the template engine what syntactic position the placeholder occupies. This allows `BuildTypePreamble` to dispatch on kind and generate appropriate scaffold code for each position. New factory methods `Capture.Type()` and `Capture.Name()` create captures with the correct kind pre-set while preserving compile-time type safety via the generic parameter. * C#: Add dependencies parameter and Capture.Expression factory - Thread `dependencies` (IReadOnlyDictionary<string, string>) through CSharpTemplate.Create, CSharpPattern.Create, and TemplateEngine.Parse for future NuGet-based type attribution during scaffold parsing - Include dependencies in the template cache key - Add Capture.Expression() factory with explicit CaptureKind.Expression - Update Of<T> docs to steer toward position-specific factories * C#: Add DependencyWorkspace for NuGet-backed type attribution in templates When templates or patterns specify NuGet dependencies, the scaffold is now parsed with a SemanticModel backed by resolved package references. This enables Roslyn to attribute types from external packages (e.g., Newtonsoft.Json.JsonConvert) during template parsing. Uses Microsoft.CodeAnalysis.Testing.ReferenceAssemblies for NuGet resolution — no subprocess or temp .csproj needed. Resolved references are cached by dependency set hash.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
DependencyWorkspacethat resolves NuGet packages into RoslynMetadataReferences usingMicrosoft.CodeAnalysis.Testing.ReferenceAssemblies— no subprocess or temp.csprojneededdependenciesare provided toCSharpTemplate.CreateorCSharpPattern.Create, the scaffold is parsed with aSemanticModelbacked by resolved package references, enabling type attribution from external packagesCaptureKindenum and position-specific factories (Capture.Expression,Capture.Type,Capture.Name) from C#: AddCaptureKindto template captures for position-aware scaffolding #7059Test plan
MethodType.DeclaringType == "Newtonsoft.Json.JsonConvert")MethodType == null(confirms attribution comes from the dependency)