Convert mpc and msbuild task package to a roslyn source generator by AArnott · Pull Request #1599 · MessagePack-CSharp/MessagePack-CSharp · GitHub
Skip to content

Convert mpc and msbuild task package to a roslyn source generator#1599

Merged
AArnott merged 97 commits into
developfrom
sourceGenerator1495
Apr 12, 2023
Merged

Convert mpc and msbuild task package to a roslyn source generator#1599
AArnott merged 97 commits into
developfrom
sourceGenerator1495

Conversation

@AArnott

@AArnott AArnott commented Apr 12, 2023

Copy link
Copy Markdown
Collaborator

This completely replaces mpc and the msbuild task package with a C# roslyn Source Generator.

NuGet package impact:

Package Impact
MessagePack.MSBuild.Tasks Deprecated, and no longer built. This carried the msbuild integration that ran source generation before invoking the compiler. Users should stop referencing it and switch to MessagePack.SourceGenerator
MessagePack.Generator Deprecated, and no longer built. This carried the .NET CLI tool mpc. Unity users should now consume the source generator contained in the MessagePack.SourceGenerator.Unity.zip file.
MessagePack.SourceGenerator The new roslyn source generator for msbuild/VS users.
MessagePack.SourceGenerator.Unity.zip A new zip archive (not a nuget package), containing a source generator that targets Roslyn 3 for use by unity.

Ideas for future work (after this PR)

  1. Now that source generation can be totally automatic, should it just be on by default, and should we find a way to always find the generated formatters instead of requiring the user to specify the right resolver? For example, the source generator could add a [MessagePackFormatter] attribute on each [MessagePackObject] (provided the class is declared as partial) so that the default in-library resolvers will find the source generated formatter.
  2. A massive refactoring of the TypeCollector and analyzers so we don't have so much repeated and inconsistently updated code. For example, the check that the type passed to MessagePackFormatterAttribute derives from IMessagePackFormatter<T> is only performed for one possible place where the attribute can appear instead of everywhere it may appear. Field and property searches are also repeated in many places, again with inconsistent code handling them.

Remaining tasks

  • Add tests for the Roslyn3 project.
  • Confirm that this works with Unity.
  • Confirm that incremental source generation works, including that every type in the FullModel type hierarchy has functional equality comparers.
  • Stop building a roslyn3 nuget package and instead build a .zip that will be added to github releases alongside the .unitypackage we already ship.
  • Rename the Generator package to SourceGenerator so we aren't radically changing the type of an existing package, which will likely cause more confusion than no longer updating an existing package.
  • Remove diagnostic reporting from generator and add a dependency on the analyzer package.
  • Re-enable or remove the remaining Compile Remove items in the source generator test projects.
  • Unify TypeCollector across source generator and analyzer.
  • Source generator (and analyzer) to use precise assembly versioning

Closes #1495

Y-YoL and others added 30 commits December 2, 2022 21:39
- remove project dependency
- update dependency package version
The source generator will altogether deprecate this.
It presumably should be 3.8, but it doesn't compile with 3.8 at this point.
This will help with cacheability.
This was referenced Jun 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants