MessagePack.FingerprintGenerator
1.0.0
dotnet add package MessagePack.FingerprintGenerator --version 1.0.0
NuGet\Install-Package MessagePack.FingerprintGenerator -Version 1.0.0
<PackageReference Include="MessagePack.FingerprintGenerator" Version="1.0.0" />
<PackageVersion Include="MessagePack.FingerprintGenerator" Version="1.0.0" />
<PackageReference Include="MessagePack.FingerprintGenerator" />
paket add MessagePack.FingerprintGenerator --version 1.0.0
#r "nuget: MessagePack.FingerprintGenerator, 1.0.0"
#:package MessagePack.FingerprintGenerator@1.0.0
#addin nuget:?package=MessagePack.FingerprintGenerator&version=1.0.0
#tool nuget:?package=MessagePack.FingerprintGenerator&version=1.0.0
MessagePack Fingerprint Generator
MessagePack Fingerprint Generator is a set of Roslyn incremental source generators that provides deterministic fingerprints and usage registries for MessagePackObject
-annotated types across a solution.
This generator is intended for developers who use MessagePack-CSharp and need to:
- Generate content-stable fingerprints for serializable types
- Reference those fingerprints at runtime
📦 Package Contents
This generator project contains two incremental source generators:
1. MessagePackFingerprintGenerator
Generates a static class containing SHA256-based fingerprints for all MessagePackObject
types declared in the current project.
Example output (generated file):
namespace MyProject.GeneratedFingerprints;
public static class MessagePackFingerprints
{
public static readonly string MyProject_MyType = ShaHelper("""
...content-dependent fingerprint seed...
""");
}
2. MessagePackRegistryGenerator
Generates a switch-based registry of all MessagePackObject
types referenced in the current assembly—regardless of where they are declared.
This allows consumers to dynamically inspect, map, or emit fingerprints only for the types they actually use.
🧠 Performance & Multi-project Setup
To fully benefit from incremental build performance, you should configure the generator in each project that:
- Declares
[MessagePackObject]
types and/or - Consumes them (e.g. via method parameters,
new
expressions, or collections)
This ensures:
- ✅ Fast builds: Only changed files/types are re-evaluated per project
- ✅ Accurate discovery: Each project emits fingerprints and registry entries for the types it actually uses
- ✅ Modular output: Generators scale across large solutions without scanning the entire dependency graph from a single root
💡 You must tell the generator what other projects it is installed in. That can be done in your .csproj
files or globally in your Directory.Build.props
file:
<Project>
<ItemGroup>
<CompilerVisibleProperty Include="MessagePackFingerprintReferencedWithGenerator" />
</ItemGroup>
<PropertyGroup>
<MessagePackFingerprintReferencedWithGenerator>MessagePackApp,LibraryWithGenerator</MessagePackFingerprintReferencedWithGenerator>
</PropertyGroup>
</Project>
Demo
This repository includes a demo app (MessagePackApp
) that showcases how the fingerprint generator works in practice. The app references types from two libraries – one that uses the generator and one that doesn't – and prints out the fingerprints of all relevant MessagePackObject
-annotated types that are actually used.
Sample Output
🎯 MessagePack Demo App
📦 Types used:
LibraryWithGenerator.DemoStruct
LibraryWithGenerator.DemoRecordStruct
LibraryWithGenerator.DemoRecord
LibraryWithGenerator.KeyAsPropClass
LibraryWithGenerator.IgnoreMemberClass
LibraryWithGenerator.DerivedClass
LibraryWithGenerator.Dog
LibraryWithGenerator.Cat
LibraryWithGenerator.ComposedClass
LibraryWithGenerator.NullableCollections
LibraryWithoutGenerator.RecordWithoutGenerator
LibraryWithoutGenerator.StructWithoutGenerator
LibraryWithoutGenerator.TreeNodeWithoutGenerator
🔐 Fingerprints:
DemoStruct: 2E1AE44C
DemoRecordStruct: 08C5B370
DemoRecord: E443845A
KeyAsPropClass: B0574CB3
IgnoreMemberClass: D90C6E60
DerivedClass: 4EB96C23
Dog: 75F5F586
Cat: 8A08F5C0
ComposedClass: 8656637D
NullableCollections: 27869092
RecordWithoutGenerator: B3CB0C34
StructWithoutGenerator: B7D2293E
TreeNodeWithoutGenerator: E607E32F
✅ Done!
🚀 Usage
Reference the generator project or NuGet package in each MessagePack-using project.
Annotate your serializable types with
[MessagePackObject]
.(Optional) Pass a build property to indicate referenced projects that also use this generator:
In your
.csproj
:<PropertyGroup> <MessagePackFingerprintReferencedWithGenerator>ProjectA,ProjectB</MessagePackFingerprintReferencedWithGenerator> </PropertyGroup>
Access fingerprints at runtime:
var fingerprint = GeneratedFingerprints.MessagePackFingerprints.MyProject_MyType;
(Optional) Use the registry:
var fingerprint = GeneratedRegistry.MessagePackFingerprintRegistry.GetFingerprint(myObject);
var fingerprint = GeneratedRegistry.MessagePackFingerprintRegistry.ShortPrint(myObject);
⚙️ Compatibility
- Requires Microsoft.CodeAnalysis.CSharp 4.4.0 or higher.
- Minimum required .NET SDK: 7.0.200.
- Minimum required Visual Studio: 17.5.
- Compatible with C# source generators using incremental generator APIs.
- Tested against Roslyn 4.4.0 to ensure consistent behavior between generation and runtime.
📝 License
This project is licensed under the MIT License.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Microsoft.CodeAnalysis.CSharp (>= 4.4.0)
- Microsoft.CodeAnalysis.CSharp.Workspaces (>= 4.4.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last Updated |
---|---|---|
1.0.0 | 161 | 4/18/2025 |