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
{{ message }}
This repository was archived by the owner on Dec 12, 2020. It is now read-only.
Copy file name to clipboardExpand all lines: CHANGELOG.md
+14-3Lines changed: 14 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,24 +7,35 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
8
8
## [Unreleased]
9
9
10
+
> ⚠ There are major changes, please look at [v0.7 migration guide].
11
+
10
12
### Added
11
-
*GeneratorInCustomerSolution sample in `samples` folder
13
+
*Various samples in `samples` folder
12
14
* GitHub Actions CI
13
15
* Support for plugin dependencies! 🎉 ([#156]).
16
+
* Plugins (generators) are now easier to build using `CodeGeneration.Roslyn.Plugin.Sdk` MSBuildSdk package ([#113]).
14
17
15
18
### Changed
16
19
* .NET Core SDK version bumped to `3.1.100` ([#178]).
17
20
*`Attributes` package now targets `net20;net40` in addition to `netstandard1.0` ([#178]).
18
-
*`dotnet-codegen` now has `RollForward=Major` policy to allow it to run on newer runtimes than 2.x,
21
+
*Tool now has `RollForward=Major` policy to allow it to run on newer runtimes than 2.x,
19
22
e.g. .NET Core SDK v3.x *only* should suffice for most usage scenarios ([#178]).
20
23
* MSBuild ItemGroup used for registration of plugin paths changed to `CodeGenerationRoslynPlugin`
21
24
(was `GeneratorAssemblySearchPaths`). A warning for using old one is introduced (`CGR1002`). ([#156])
22
25
* ItemGroup now should contain full path to generator dll (previously it was a containing folder path)
23
-
* Old behavior has a compat-plug and the paths are searched for any dll, and those found are added to new ItemGroup.
26
+
* Old behavior has a compat-plug for now and the paths are searched for any dll, and those found are added to new ItemGroup.
24
27
* When using P2P generator (same solution), a consuming project needs to add an attribute `OutputItemType="CodeGenerationRoslynPlugin"` to the `ProjectReference` of the generator project. See [v0.7 migration guide].
28
+
*`dotnet-codegen` package is now `CodeGeneration.Roslyn.Tool` and is build very differently;
29
+
also it includes build assets from `BuildTime` package ([#198]).
30
+
31
+
### Removed
32
+
*`CodeGeneration.Roslyn.BuildTime` package is now merged into `CodeGeneration.Roslyn.Tool`
33
+
(which is now the only package required to be referenced by generator consumers, aside from generators themselves) ([#198]).
Copy file name to clipboardExpand all lines: README.md
+52-48Lines changed: 52 additions & 48 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -52,6 +52,7 @@ for it. That's because code generation runs *before* the consuming project is it
52
52
Now we'll use an [MSBuild project SDK]`CodeGeneration.Roslyn.Plugin.Sdk` to speed up configuring our generator plugin. Edit your project file and add the `<Sdk>` element:
53
53
54
54
```xml
55
+
<!-- Duplicator/Duplicator.csproj -->
55
56
<ProjectSdk="Microsoft.NET.Sdk">
56
57
<!-- Add the following element above any others: -->
57
58
<SdkName="CodeGeneration.Roslyn.Plugin.Sdk"Version="{replace with actual version used}"/>
@@ -141,6 +142,7 @@ with a dependency on your code generation assembly.
141
142
142
143
We'll consume our generator in a Reflector app:
143
144
> `dotnet new console -f netcoreapp2.1 -o Reflector`
145
+
>
144
146
> `dotnet add Reflector reference Duplicator`
145
147
146
148
Let's write a simple program that prints all types in its assembly:
@@ -183,14 +185,15 @@ namespace Reflector
183
185
184
186
Right now `dotnet run -p Reflector` outputs:
185
187
> `Reflector.Program`
188
+
>
186
189
> `Reflector.Test`
187
190
188
-
Now all that's left is to plumb the build pipeline with code generation tool. You'll need to add the following two references to your Reflector project file:
<!-- This reference imports targets that run the dotnet-codegen tool during build. It contains only MSBuild targets and so can be marked with PrivateAssets="all" -->
<!-- This allows the build to invoke dotnet-codegen console tool that actually
214
-
performs code generation: compiles you source files, runs plugins and saves
215
-
results adding them to the list of Compile sources for the CoreCompile step. -->
216
-
<DotNetCliToolReferenceInclude="dotnet-codegen"
217
-
Version="$(CodeGenerationRoslynVersion)" />
218
218
</ItemGroup>
219
219
</Project>
220
220
```
221
221
222
222
And if all steps were done correctly, `dotnet run -p Reflector` should print:
223
223
> `Reflector.Program`
224
+
>
224
225
> `Reflector.Test`
226
+
>
225
227
> `Reflector.TestPassed`
226
228
227
-
> ➡ Notice that there is a `TestPassed` type in the assembly now.
229
+
> 💡 Notice that there is a `TestPassed` type in the assembly now.
228
230
229
231
What's even better is that you should see that new type in IntelliSense as well!
230
232
Try executing Go to Definition (<kbd>F12</kbd>) on it - your IDE (VS/VS Code) should open the generated file for you (it'll be located in `IntermediateOutputPath` - most commonly `obj/`).
@@ -264,18 +266,27 @@ So, the consuming project will have a simple ProjectReference to the
264
266
`Duplicator.Attributes` project, and the generator project will not have
265
267
any attribute defined. With that done, we can move to the next section.
266
268
267
-
> 📋 Side note: if you use generator only in a single TFM-incompatible project,
269
+
> 📋 Side note: if there's only one consumer project for your generator,
268
270
> you can define the triggering attribute in the consuming project as well.
271
+
> In our case, this would bean moving the `DuplicateWithSuffixAttribute.cs`
272
+
> from `Duplicator` to `Reflector`, and adding a reference to the
273
+
> [`CodeGeneration.Roslyn.Attributes`][AttrNuPkg] in Reflector:
> For simplicity, we'll assume this is the case in the following sections.
269
279
270
280
### Customize generator reference
271
281
272
282
With the attribute available to consuming code, we don't need a reference to
273
283
the generator project, right? Well, not quite. The magic OutputItemType metadata
274
284
is important - it adds a path to the generator dll to the list of plugins known
275
-
to the `dotnet-codegen` tool. Additionally, we want to specify that there's a build
276
-
dependency of the consuming project on the generator. So we modify the reference:
285
+
to the `CodeGeneration.Roslyn.Tool` tool. Additionally, we want to specify that there's a build dependency of the consuming project on the generator. So we modify
0 commit comments