Add 'plugins' emitter option to load generator plugins from paths#10249
Open
JoshLove-msft wants to merge 19 commits intomicrosoft:mainfrom
Open
Add 'plugins' emitter option to load generator plugins from paths#10249JoshLove-msft wants to merge 19 commits intomicrosoft:mainfrom
JoshLove-msft wants to merge 19 commits intomicrosoft:mainfrom
Conversation
Add a new 'plugin' option to the CSharp emitter that allows specifying a path to a generator plugin assembly (DLL) or directory directly in tspconfig.yaml. This eliminates the need to create a separate npm package.json and custom emitter-package.json for custom visitors. TypeScript side: - Add 'plugin' to CSharpEmitterOptions and schema - Resolve relative paths to absolute in emitCodeModel() - The option flows through Configuration.json automatically C# side: - GeneratorHandler.LoadGenerator() reads the 'plugin' path from Configuration.AdditionalConfigurationOptions - AddConfiguredPluginDlls() loads the assembly (single DLL or directory scan) into the MEF AggregateCatalog before composition - Discovered GeneratorPlugin implementations are applied via the existing MEF [ImportMany] Plugins pipeline Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Move the 'plugin' option from AdditionalConfigurationOptions to a first-class PluginPath property on Configuration, consistent with how PackageName, DisableXmlDocs, and other known options are handled. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
|
No changes needing a change description found. |
commit: |
Support multiple plugin paths so users can load plugins from
different locations independently.
Usage:
plugin:
- path/to/PluginA.dll
- path/to/plugin-b/dist
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
C# tests (ConfigurationTests): - PluginPaths parsed from JSON array - PluginPaths null when not in config - PluginPaths null when empty array - plugins excluded from AdditionalConfigurationOptions TypeScript tests (options.test.ts): - plugins array passed through to configuration - plugins not included when not set Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
JoshLove-msft
commented
Apr 2, 2026
| description: | ||
| "Paths to generator plugin assemblies (DLLs) or directories containing plugin assemblies. " + | ||
| "Each plugin must contain a class that extends GeneratorPlugin. " + | ||
| "This eliminates the need for a separate npm package and emitter-package.json for custom visitors.", |
Contributor
Author
There was a problem hiding this comment.
we don't need this last sentence.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Both the node_modules plugin path and the 'plugins' config path now share a BuildPluginIfNeeded helper that searches for a .csproj (recursively) and runs dotnet build if found. This means plugin packages no longer need to ship pre-built DLLs — the generator builds them on demand. For node_modules plugins: if dist/ doesn't exist, falls back to searching for a .csproj in the package directory. For configured plugins: searches for a .csproj first, falls back to scanning for pre-built DLLs. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- BuildPlugin_BuildsProjectAndReturnsDllPath: creates a minimal .csproj + .cs file in a temp directory, builds it, and verifies the output DLL path is returned and exists on disk. - BuildPlugin_ThrowsOnInvalidProject: verifies that an invalid .csproj throws InvalidOperationException. Also made BuildPlugin internal (was private) so it can be tested directly. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- BuildPluginIfNeeded_ReturnsNullWhenNoCsproj: directory with no .csproj returns null - BuildPluginIfNeeded_FindsCsprojInSubdirectory: .csproj nested in a subdirectory is found and built - BuildPlugin_OutputDllContainsCompiledType: verifies the built DLL actually contains the compiled types via reflection Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- NoPluginPaths: null PluginPaths is a no-op (0 catalogs added) - InvalidDirectory: nonexistent path throws InvalidOperationException - DirectoryWithPreBuiltDlls: loads pre-built DLLs when no .csproj - DirectoryWithCsproj: auto-builds and loads the plugin - MultiplePluginPaths: handles mixed pre-built + .csproj paths Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This reverts commit d6605c0.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
jsquire
approved these changes
Apr 2, 2026
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
JonathanCrd
approved these changes
Apr 2, 2026
Collaborator
|
You can try these changes here
|
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
JonathanCrd
approved these changes
Apr 3, 2026
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.
Problem
Fixes #8196
Defining custom visitors currently requires creating a separate npm package (with package.json) and a custom �mitter-package.json to reference it. This is heavy ceremony for what should be a simple task.
Solution
Add a \plugins\ emitter option to @typespec/http-client-csharp\ that accepts an array of paths to plugin assemblies (DLLs) or directories. The generator loads plugins from these paths using the existing MEF composition pipeline.
Usage
\\yaml
options:
"@typespec/http-client-csharp":
plugins:
- path/to/MyPlugin.dll
- path/to/another-plugin/dist
\\
Each plugin must contain a class extending \GeneratorPlugin.
What this eliminates
Changes
TypeScript emitter:
C# generator: