Skip to content

build: target netstandard2.1, net8.0 and net10.0 - #478

Open
aetos382 wants to merge 7 commits into
Cysharp:mainfrom
aetos382:build/tfm-net10
Open

aetos382 wants to merge 7 commits into
Cysharp:mainfrom
aetos382:build/tfm-net10

Conversation

@aetos382

Copy link
Copy Markdown
Contributor

Note

This PR is based on #468 and includes its two commits. Please merge #468 first. The changes of this PR are the last four commits.

Summary

.NET 6 and .NET 7 are out of support, and .NET 10 is the current LTS. This PR drops net6.0 and net7.0, adds net10.0, and keeps net8.0.

Package Before After
MemoryPack, MemoryPack.Core, MemoryPack.UnityShims net7.0;net8.0;netstandard2.1 netstandard2.1;net8.0;net10.0
MemoryPack.Streaming net7.0;netstandard2.1 netstandard2.1;net8.0;net10.0
MemoryPack.AspNetCoreMvcFormatter net6.0;net7.0 net8.0;net10.0

MemoryPack.Streaming gets net8.0 so that .NET 8 apps keep using the net* builds of both MemoryPack.Core and MemoryPack.Streaming.

Dependency versions are not changed in this PR.

Changes

  • Source generator: The generator decides what to emit from the preprocessor symbols of the consuming project. Apps on .NET 7 now resolve to the netstandard2.1 build, so the check is changed from NET7_0_OR_GREATER to NET8_0_OR_GREATER.
  • #if: In MemoryPack.Core, NET5_0_OR_GREATER, NET7_0_OR_GREATER and NET8_0_OR_GREATER all mean "not the netstandard2.1 build" now, so they are replaced with NETSTANDARD (107 places, including the .tt template). The code generated by the source generator ([ModuleInitializer] under #if NET5_0_OR_GREATER) and the test code keep the original symbols, because they are compiled with the symbols of the consuming project.
  • MemoryPack.Streaming: System.IO.Pipelines is referenced only below net9.0. It is part of the shared framework in .NET 9 or later.
  • Tests: MemoryPack.Tests runs on net8.0 and net10.0, and MemoryPack.Tests.NetStandard runs on net10.0. The default preprocessor symbols of CSharpGeneratorRunner include NET8_0_OR_GREATER.
  • Sandbox: Net6VsNet7 and SandboxNet6 are removed. SandboxWebApp targets net10.0.
  • README: Recommends .NET 10, updates "Target framework dependency" (library authors should multi-target netstandard2.1;net8.0), and removes the note about the .NET 7 Native AOT crash.

Impact on consumers

Apps on .NET 7 resolve to the netstandard2.1 build of MemoryPack. With the generator change above, most of them keep working, but they break if they:

  • use APIs that exist only in the net* builds, such as a struct IBufferWriter<byte> (build error);
  • use a library that ships a net7.0 asset built against MemoryPack, as the README recommended (MissingMethodException at run time); or
  • serialize IReadOnlySet<T> or PriorityQueue<TElement, TPriority> (MemoryPackSerializationException at run time).

They also lose some fast paths of the net* builds. For example, deserializing List<T> adds the elements one by one instead of using CollectionsMarshal.SetCount, and ImmutableArray<T> is created from a copy.

MemoryPack.AspNetCoreMvcFormatter no longer supports .NET 6 and .NET 7.

These apps need to move to .NET 8 or later, or stay on 1.22.x. When they move to .NET 10, note that DateTimeOffset serialized on .NET 9 or lower can not be deserialized correctly as DateTimeOffset (see Net10DateTimeOffset and MEMPACK043).

The wire format is not changed. Apps on .NET 8 or later, apps on .NET 6 or lower (except MemoryPack.AspNetCoreMvcFormatter users), and Unity are not affected.

🤖 Generated with Claude Code

aetos382 and others added 6 commits November 12, 2026 14:42
Add MemoryPack.Tests.NetStandard, which links the sources of
MemoryPack.Tests and references MemoryPack.Core and MemoryPack.Streaming
with SetTargetFramework=netstandard2.1. NET*_OR_GREATER symbols are
disabled so that test code and generated code take the same path as
netstandard2.1 consumers (e.g. Unity).

- Exclude source generator tests and MemoryLayoutTest, which do not
  depend on the target framework of the libraries.
- Skip SerializerStructBufferWriterTest when NET7_0_OR_GREATER is not
  defined, because the netstandard2.1 build requires TBufferWriter to be
  a reference type.
- Register external union formatters manually in UnionTest when
  NET5_0_OR_GREATER is not defined, because generated initializers have
  [ModuleInitializer] only in that case.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Microsoft.NET.Test.Sdk 17.3.1 is distributed under the Microsoft .NET
Library license (LICENSE_NET.txt), which is not in the allow list of
dependency-review. 17.10.0 and later use the MIT license expression.

Update both test projects to the same version, because they share the
same test sources.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Drop net7.0 from the libraries and add net10.0. MemoryPack.Streaming
  also gets net8.0, so that .NET 8 apps keep using the net* builds of
  both MemoryPack.Core and MemoryPack.Streaming.
- MemoryPack.AspNetCoreMvcFormatter: net6.0;net7.0 -> net8.0;net10.0.
- The source generator switches the generated code by
  NET8_0_OR_GREATER instead of NET7_0_OR_GREATER, because apps on
  .NET 7 or lower now resolve to the netstandard2.1 build. MEMPACK034
  keeps NET7_0_OR_GREATER, as it is about the struct layout of the
  runtime.
- Reference System.IO.Pipelines only below net9.0. It is part of the
  shared framework in .NET 9 or later.
- Run the tests on net8.0 and net10.0, and the netstandard2.1 tests on
  net10.0.
- SandboxWebApp: net7.0 -> net10.0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Now that net7.0 is dropped, NET5_0_OR_GREATER, NET7_0_OR_GREATER and
NET8_0_OR_GREATER all mean "not the netstandard2.1 build" in
MemoryPack.Core. The behavior of each build is not changed.

The code generated by the source generator and the test code keep the
original symbols, because they are compiled with the symbols of the
consuming project.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
They target net6.0 and net7.0, which are out of support. Net6VsNet7
compared the .NET 6 and .NET 7 runtimes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Recommend .NET 10 instead of .NET 7.
- Target framework dependency: library authors should multi-target
  netstandard2.1 and net8.0 instead of net7.0.
- Remove the note about the .NET 7 Native AOT crash, which was fixed
  in .NET 8.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Cross-framework test parallelism can cause concurrent access to the shared temporary FullName.ts file, leading to sharing errors, incomplete reads, and intermittent test failures.

1 open issue
What changed in this PR

Modernizes MemoryPack’s framework targets and aligns generated serializers with the selected library build. It also incorporates #468’s test coverage for the .NET Standard implementation.

Changes:

  • Replace .NET 6/7 package targets with .NET 8/10, retaining .NET Standard 2.1 where supported.
  • Simplify Core’s conditional compilation and select modern generator output starting with .NET 8.
  • Expand test targets, remove legacy sandboxes, and refresh compatibility guidance.
File Description
tests/​MemoryPack.Tests/​Utils/​CSharpGeneratorRunner.cs Add the default .NET 8 generator symbol.
tests/​MemoryPack.Tests/​UnionTest.cs Register union formatters when module initializers are unavailable.
tests/​MemoryPack.Tests/​SerializerStructBufferWriterTest.cs Exclude unsupported struct-writer tests from standard-build coverage.
tests/​MemoryPack.Tests/​MemoryPack.Tests.csproj Test .NET 8/10 and update the test SDK.
tests/​MemoryPack.Tests.NetStandard/​MemoryPack.Tests.NetStandard.csproj Run shared tests against standard assets on .NET 10.
src/​MemoryPack/​MemoryPack.csproj Update meta-package framework targets.
src/​MemoryPack.UnityShims/​MemoryPack.UnityShims.csproj Update Unity shims framework targets.
src/​MemoryPack.Streaming/​MemoryPack.Streaming.csproj Update targets and condition the Pipelines dependency.
src/​MemoryPack.Generator/​MemoryPackGenerator.Emitter.cs Gate modern generated code on .NET 8.
src/​MemoryPack.Generator/​MemoryPackGenerator.cs Track consuming projects’ .NET 8 symbols.
src/​MemoryPack.Generator/​IGeneratorContext.cs Separate asset-selection and runtime-layout flags.
src/​MemoryPack.Core/​MemoryPackWriterOptionalState.cs Simplify reference-tracking compilation guards.
src/​MemoryPack.Core/​MemoryPackWriter.cs Simplify writer implementation and constraint guards.
src/​MemoryPack.Core/​MemoryPackSerializerOptions.cs Restrict compatibility support to standard builds.
src/​MemoryPack.Core/​MemoryPackSerializer.Serialize.cs Simplify serialization fast-path and constraint guards.
src/​MemoryPack.Core/​MemoryPackSerializer.NonGenerics.cs Simplify non-generic serialization constraint guards.
src/​MemoryPack.Core/​MemoryPackSerializer.Deserialize.cs Simplify trimming-annotation guards.
src/​MemoryPack.Core/​MemoryPackReader.cs Simplify reader implementation guards.
src/​MemoryPack.Core/​MemoryPackFormatterProvider.WellknownTypes.tt Update formatter-registration template guards.
src/​MemoryPack.Core/​MemoryPackFormatterProvider.WellknownTypes.cs Update generated formatter-registration guards.
src/​MemoryPack.Core/​MemoryPackFormatterProvider.cs Simplify formatter registration and discovery guards.
src/​MemoryPack.Core/​MemoryPack.Core.csproj Target .NET Standard 2.1 and .NET 8/10.
src/​MemoryPack.Core/​Internal/​TypeHelpers.cs Simplify fixed-size packable detection guards.
src/​MemoryPack.Core/​Internal/​ReusableReadOnlySequenceBuilder.cs Simplify span-based iteration guards.
src/​MemoryPack.Core/​Internal/​ReusableLinkedArrayBufferWriter.cs Simplify buffer optimizations and constraint guards.
src/​MemoryPack.Core/​Internal/​MemoryMarshalEx.cs Limit compatibility helpers to standard builds.
src/​MemoryPack.Core/​Internal/​EnumerableExtensions.cs Simplify collection-count optimization guards.
src/​MemoryPack.Core/​IMemoryPackFormatter.cs Simplify formatter buffer-writer constraint guards.
src/​MemoryPack.Core/​IMemoryPackable.cs Simplify static-abstract interface guards.
src/​MemoryPack.Core/​Formatters/​TypeFormatter.cs Simplify generated-regex guards.
src/​MemoryPack.Core/​Formatters/​StringBuilderFormatter.cs Simplify optimized string-builder serialization guards.
src/​MemoryPack.Core/​Formatters/​MultiDimensionalArrayFormatters.cs Simplify unmanaged-array fast-path guards.
src/​MemoryPack.Core/​Formatters/​MemoryPackableFormatter.cs Limit the modern formatter to nonstandard builds.
src/​MemoryPack.Core/​Formatters/​KeyValuePairFormatter.cs Simplify buffer-writer constraint guards.
src/​MemoryPack.Core/​Formatters/​InterfaceCollectionFormatters.cs Simplify collection support and optimization guards.
src/​MemoryPack.Core/​Formatters/​ImmutableCollectionFormatters.cs Simplify immutable-array deserialization guards.
src/​MemoryPack.Core/​Formatters/​FrozenCollectionFormatter.cs Enable frozen collections in nonstandard builds.
src/​MemoryPack.Core/​Formatters/​CollectionFormatters.cs Simplify collection fast-path and availability guards.
src/​MemoryPack.Core/​Compression/​BrotliCompressor.cs Simplify compressor implementation and API guards.
src/​MemoryPack.Core/​Compression/​BitPackFormatter.cs Simplify vectorized bit-packing guards.
src/​MemoryPack.AspNetCoreMvcFormatter/​MemoryPack.AspNetCoreMvcFormatter.csproj Target ASP.NET Core 8/10.
sandbox/​SandboxWebApp/​SandboxWebApp.csproj Move the web sandbox to .NET 10.
sandbox/​SandboxNet6/​SandboxNet6.csproj Remove the .NET 6 sandbox project.
sandbox/​SandboxNet6/​Program.cs Remove legacy sandbox examples.
sandbox/​SandboxNet6/​NamespaceTest.cs Remove the legacy namespace example.
sandbox/​Net6VsNet7/​Program.cs Remove .NET 6/7 comparison benchmarks.
sandbox/​Net6VsNet7/​Net6VsNet7.csproj Remove the legacy benchmark project.
README.md Update framework guidance and remove the obsolete AOT warning.
MemoryPack.sln Add standard-build tests and remove legacy sandboxes.

Review effort: Balanced


<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFrameworks>net8.0;net10.0</TargetFrameworks>
The tests of each target framework run in parallel with the .NET 9 SDK
or later, and the TypeScript generator tests wrote the same files
(such as FullName.ts and MemoryPackWriter.ts) into the temp directory.
Each TypeScriptOptionProvider now creates its own directory with
Directory.CreateTempSubdirectory and deletes it when disposed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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