|
2 | 2 |
|
3 | 3 | Provides the functionality to bind an object to data in configuration providers for [Microsoft.Extensions.Configuration](https://www.nuget.org/packages/Microsoft.Extensions.Configuration/).
|
4 | 4 |
|
5 |
| -Documentation can be found at https://learn.microsoft.com/dotnet/core/extensions/configuration |
| 5 | +Documentation can be found at https://learn.microsoft.com/dotnet/core/extensions/configuration. |
6 | 6 |
|
7 | 7 | ## Contribution Bar
|
8 | 8 | - [x] [We consider new features, new APIs, bug fixes, and performance changes](../README.md#contribution-bar)
|
@@ -89,3 +89,42 @@ You can include a configuration file using a code like this in your `.csproj` fi
|
89 | 89 | </Content>
|
90 | 90 | </ItemGroup>
|
91 | 91 | ```
|
| 92 | + |
| 93 | +## Contributing changes to the source generator |
| 94 | + |
| 95 | +Along with the binder assembly that uses reflection, we ship a source generator assembly that provides a reflection and AOT compatible implementation. It works by intercepting regular binding calls and redirecting them to new routines that execute strongly typed binding logic. |
| 96 | + |
| 97 | +### Worfklow |
| 98 | + |
| 99 | +- [Build the .NET libraries and runtime assemblies](https://github.com/dotnet/runtime/tree/7ed33d80c92fa0b7ae740df60a460e984f2f442b#how-can-i-contribute) |
| 100 | +- Make the generator changes in the `gen\` directory |
| 101 | +- Validate the changes by running the source generator tests in `tests\SourceGeneratorTests` |
| 102 | + |
| 103 | +### Testing |
| 104 | + |
| 105 | +Here's a general command for running the the generator tests. They assume that you're making the changes in a Windows OS and running the from the `tests\SourceGeneratorTests\` directory. |
| 106 | + |
| 107 | +```ps |
| 108 | +dotnet build /t:test |
| 109 | +``` |
| 110 | + |
| 111 | +If applicable, add new tests to validate your contribution. See [this documentation](https://github.com/dotnet/runtime/blob/7ed33d80c92fa0b7ae740df60a460e984f2f442b/docs/workflow/README.md#full-instructions-on-building-and-testing-the-runtime-repo) for details. |
| 112 | + |
| 113 | +#### Stale generator bits |
| 114 | + |
| 115 | +Sometimes the SDK uses stale bits of the generator. This can lead to unexpected test behavior or failures. Killing `dotnet.exe` processes usually solves the issue, e.g. with `taskkill /F /IM dotnet.exe /T`. |
| 116 | + |
| 117 | +#### Updating baselines |
| 118 | + |
| 119 | +Some contributions might change the logic emitted by the generator. We maintain baseline [source files](https://github.com/dotnet/runtime/tree/e3e9758a10870a8f99a93a25e54ab2837d3abefc/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/Baselines) to track the code emitted to handle some core binding scenarios. |
| 120 | + |
| 121 | +If the emitted code changes, these tests will fail locally and in continuous integration checks (for PRs) changes. You would need to update the baseline source files, manually or by using the following commands (PowerShell): |
| 122 | + |
| 123 | +```ps |
| 124 | +> $env:RepoRootDir = "D:\repos\dotnet_runtime" |
| 125 | +> dotnet build t:test -f /p:UpdateBaselines=true |
| 126 | +``` |
| 127 | + |
| 128 | +We have a [test helper](https://github.com/dotnet/runtime/blob/e3e9758a10870a8f99a93a25e54ab2837d3abefc/src/libraries/Microsoft.Extensions.Configuration.Binder/tests/SourceGenerationTests/GeneratorTests.Helpers.cs#L105-L118) to update the baselines. It requires setting an environment variable called `RepoRootDir` to the root repo path. In additon, the `UpdateBaselines` MSBuild property needs to be set to `true`. |
| 129 | + |
| 130 | +After updating the baselines, inspect the changes to verify that they are valid. Note that the baseline tests will fail if the new code causes errors when building the resulting compilation. |
0 commit comments