GeezerVison is showing github.com — Convert mpc and msbuild task package to a roslyn source generator by AArnott · Pull Request #1599 · MessagePack-CSharp/MessagePack-CSharp
Conversation
AArnott
commented
Apr 12, 2023
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
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)
- 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.
- 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
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
- 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 Nov 9, 2026
This was referenced Nov 16, 2026
This was referenced Nov 23, 2026
Reviewers
neuecc
Awaiting requested review from neuecc
1 more reviewer
Y-YoL
Y-YoL left review comments
Reviewers whose approvals may not affect merge requirements
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.