You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add 'plugins' emitter option to load generator plugins from paths (#10249)
## 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
- npm \package.json\ wrapper for plugin DLLs
- Custom \�mitter-package.json\ with plugin dependency
- Custom \�mitterPackageJsonPath\ in \ sp-location.yaml\
### Changes
**TypeScript emitter:**
- \options.ts\ — Added \plugins\ to \CSharpEmitterOptions\ interface and
JSON schema (\string[]\)
- \�mitter.ts\ — Resolves relative paths to absolute before writing to
Configuration.json
**C# generator:**
- \Configuration.cs\ — Added \PluginPaths\ as a top-level property
(\IReadOnlyList<string>?\)
- \GeneratorHandler.cs\ — Added \AddConfiguredPluginDlls()\ that loads
plugin assemblies into the MEF \AggregateCatalog\ before composition, so
they participate in the same discovery pipeline as node_modules plugins
---------
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The config can be extended with options as follows:
21
+
22
+
```yaml
23
+
emit:
24
+
- "@typespec/http-client-csharp"
25
+
options:
26
+
"@typespec/http-client-csharp":
27
+
option: value
28
+
```
29
+
30
+
## Emitter options
31
+
32
+
### `emitter-output-dir`
33
+
34
+
**Type:** `absolutePath`
35
+
36
+
Defines the emitter output directory. Defaults to `{output-dir}/@typespec/http-client-csharp`
37
+
See [Configuring output directory for more info](https://typespec.io/docs/handbook/configuration/configuration/#configuring-output-directory)
38
+
39
+
### `api-version`
40
+
41
+
**Type:** `string`
42
+
43
+
For TypeSpec files using the [`@versioned`](https://typespec.io/docs/libraries/versioning/reference/decorators/#@TypeSpec.Versioning.versioned) decorator, set this option to the version that should be used to generate against.
44
+
45
+
### `generate-protocol-methods`
46
+
47
+
**Type:** `boolean`
48
+
49
+
Set to `false` to skip generation of protocol methods. The default value is `true`.
50
+
51
+
### `generate-convenience-methods`
52
+
53
+
**Type:** `boolean`
54
+
55
+
Set to `false` to skip generation of convenience methods. The default value is `true`.
Defines the strategy on how to handle unreferenced types. The default value is `removeOrInternalize`.
62
+
63
+
### `new-project`
64
+
65
+
**Type:** `boolean`
66
+
67
+
Set to `true` to overwrite the csproj if it already exists. The default value is `false`.
68
+
69
+
### `save-inputs`
70
+
71
+
**Type:** `boolean`
72
+
73
+
Set to `true` to save the `tspCodeModel.json` and `Configuration.json` files that are emitted and used as inputs to the generator. The default value is `false`.
74
+
75
+
### `package-name`
76
+
77
+
**Type:** `string`
78
+
79
+
Define the package name. If not specified, the first namespace defined in the TypeSpec is used as the package name.
80
+
81
+
### `debug`
82
+
83
+
**Type:** `boolean`
84
+
85
+
Set to `true` to automatically attempt to attach to a debugger when executing the C# generator. The default value is `false`.
86
+
87
+
### `logLevel`
88
+
89
+
**Type:** `"info" | "debug" | "verbose"`
90
+
91
+
Set the log level for which to collect traces. The default value is `info`.
92
+
93
+
### `disable-xml-docs`
94
+
95
+
**Type:** `boolean`
96
+
97
+
Set to `true` to disable XML documentation generation. The default value is `false`.
98
+
99
+
### `generator-name`
100
+
101
+
**Type:** `string`
102
+
103
+
The name of the generator. By default this is set to `ScmCodeModelGenerator`. Generator authors can set this to the name of a generator that inherits from `ScmCodeModelGenerator`.
104
+
105
+
### `emitter-extension-path`
106
+
107
+
**Type:** `string`
108
+
109
+
Allows emitter authors to specify the path to a custom emitter package, allowing you to extend the emitter behavior. This should be set to `import.meta.url` if you are using a custom emitter.
110
+
111
+
### `plugins`
112
+
113
+
**Type:** `array`
114
+
115
+
Paths to generator plugin assemblies (DLLs) or directories containing plugin assemblies. Each plugin must contain a class that extends GeneratorPlugin.
116
+
117
+
### `license`
118
+
119
+
**Type:** `object`
120
+
121
+
License information for the generated client code.
122
+
123
+
### `sdk-context-options`
124
+
125
+
**Type:** `object`
126
+
127
+
The SDK context options that implement the `CreateSdkContextOptions` interface from the [`@azure-tools/typespec-client-generator-core`](https://www.npmjs.com/package/@azure-tools/typespec-client-generator-core) package to be used by the CSharp emitter.
"Allows emitter authors to specify the path to a custom emitter package, allowing you to extend the emitter behavior. This should be set to `import.meta.url` if you are using a custom emitter.",
115
116
},
117
+
plugins: {
118
+
type: "array",
119
+
items: {type: "string"},
120
+
nullable: true,
121
+
description:
122
+
"Paths to generator plugin assemblies (DLLs) or directories containing plugin assemblies. "+
123
+
"Each plugin must contain a class that extends GeneratorPlugin.",
0 commit comments