Skip to content

Commit

Permalink
Add note for issue 51692 to source generator cookbooks
Browse files Browse the repository at this point in the history
Adds notes to the source generator cookbooks documenting issue #51692,
where CompilerVisibleProperty values provided to source generators are
lost/damaged in transport as a result of being dumped verbatim into an
INI file.
  • Loading branch information
jcracknell committed Jan 20, 2025
1 parent 22afb85 commit 8c4fcfe
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
15 changes: 15 additions & 0 deletions docs/features/incremental-generators.cookbook.md
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,21 @@ In the users project file, the user can now annotate the individual additional f
</ItemGroup>
```

Note that MSBuild properties passed to source generators via `CompilerVisibleProperty` are currently dumped verbatim into and read from an INI file, [resulting in data loss for non-trivial property values](https://github.com/dotnet/roslyn/issues/51692). One possible workaround is to use a build task to apply a transport encoding preventing the data loss; as an example a semicolon separated list can be converted to a space separated list (`;` is the INI comment character):

```c#
<Project>
<ItemGroup>
<CompilerVisibleProperty Include="_MyInterpolatorsNamespaces" />
</ItemGroup>
<Task Name="_MyInterpolatorsNamespaces" BeforeTargets="BeforeBuild">
<PropertyGroup>
<_MyInterpolatorsNamespaces>$([System.String]::Copy('$(InterpolatorsNamespaces)').Replace(';', ' '))</_MyInterpolatorsNamespaces>
</PropertyGroup>
</Task>
</Project>
```

**Full Example:**

MyGenerator.props:
Expand Down
15 changes: 15 additions & 0 deletions docs/features/source-generators.cookbook.md
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,21 @@ In the users project file, the user can now annotate the individual additional f
</ItemGroup>
```

Note that MSBuild properties passed to source generators via `CompilerVisibleProperty` are currently dumped verbatim into and read from an INI file, [resulting in data loss for non-trivial property values](https://github.com/dotnet/roslyn/issues/51692). One possible workaround is to use a build task to apply a transport encoding preventing the data loss; as an example a semicolon separated list can be converted to a space separated list (`;` is the INI comment character):

```c#
<Project>
<ItemGroup>
<CompilerVisibleProperty Include="_MyInterpolatorsNamespaces" />
</ItemGroup>
<Task Name="_MyInterpolatorsNamespaces" BeforeTargets="BeforeBuild">
<PropertyGroup>
<_MyInterpolatorsNamespaces>$([System.String]::Copy('$(InterpolatorsNamespaces)').Replace(';', ' '))</_MyInterpolatorsNamespaces>
</PropertyGroup>
</Task>
</Project>
```

**Full Example:**

MyGenerator.props:
Expand Down

0 comments on commit 8c4fcfe

Please sign in to comment.