-
Notifications
You must be signed in to change notification settings - Fork 392
Restore netstandard2.0 support for Mapster #849
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: development
Are you sure you want to change the base?
Conversation
|
CI on ubuntu-latest fails trying to run net48 test targets because the runner image no longer has This PR now gates |
|
Correction: the MSBuild property is Net48 test targets are now gated behind |
Hi @DocSvartz. Windows (x86): including .NET Framework 4.8 (net48) (also net8.0/net9.0/net10.0) — 1,489 tests (0 failed) |
|
@asp2286 Ok 👍
|
@DocSvartz |
Fixes MapsterMapper#639 Includes packaging changes to ship a netstandard2.0 assembly again, plus test/CI updates to keep net48 tests running only on Windows.
1b59b75 to
15a8f22
Compare
|
@DocSvartz @asp2286 would prefer, if you would:
|
|
@DevTKSS I might be wrong, but potential incompatibility can occur if the machine has a runtime that doesn't support a LangVersion higher than the one set during compilation? |
|
@DocSvartz you can use net8 with all lower but if the user is not having net8+ then instead maybe only framework, he will get errors when the project here is using a specific hogher lang version. Thats why I would not set it explicitly then instead rely on the net standard 2.0 to provide all it needs and only those things it is meant to be capable of! |
|
@DevTKSS Yes, But then all the code would have to be downgrade to like netstandard2.0. And only those parts that will give performance in the new TFMs can be rewritten using #if NET8_OR_GREATER Otherwise, it will be a spaghetti monster of #if constructions 😅 (at least netstandard2.0 no nullable reference type) |
@DocSvartz 🤔 ehm... but this downgrading seems to be exactly what this PR suggests, "just" to have the netstandard2.0 and Framework compartibility:
and and the "Spagetti Monster" how you call the Conditionals is not as worse as it seems: and the "Spagetti Monster" how you call the Conditionals is not as worse as it seems. Of course, it adds some lines, but in my opinion this is simply the price of keeping legacy targets (even Microsoft does not actively bring out Framework features anymore) and let's assume realistically, this PR is about the But yes, I totally can understand them too! I was also annoyed of e.g. the cool Source Generators like CommunityToolkit.Mvvm was having has not been supported or relyable use-able with that Framework App I tryed to enhance with it! |
@DevTKSS I'm not against multi-targeting either.
As far as I understand, you are suggesting to adhere to approach number 2? Example |
|
@DocSvartz, @DevTKSS Regarding LangVersion LangVersion is a compile-time setting only and does not affect runtime compatibility. A few important points for context: C# 7.3 does not support nullable reference types. The Mapster codebase already uses C# 8+ features (nullable reference types, notnull constraint, etc.) in projects targeting netstandard2.0 / net48. Without an explicit LangVersion, the SDK defaults those TFMs to C# 7.3, which fails to compile. All supported .NET Framework versions can consume IL produced by C# 12, since language support depends on the Roslyn compiler, not on the target runtime. Visual Studio 2022 (17.7+) fully supports C# 12 and is the current recommended development environment. I have locally tested LangVersion=12 from .NET Framework 3.5 SP1 through 4.8.1 in Visual Studio 2022 — builds and runtime behavior are correct. The only potential limitation is Visual Studio 2019 (max C# 9), but its mainstream support ended in April 2024. Given that the codebase already requires C# 8+ semantics, explicitly setting LangVersion reflects the existing reality and avoids silent SDK defaults that lead to build failures on netstandard2.0 / net48. Could you please let me know what approach you’d prefer here? |
@DevTKSS Fully agree — I’ll rework the PR to keep modern NET8+ code paths intact and isolate netstandard2.0 fallbacks in centralized compat helpers. |
|
One more clarification regarding language version vs. platform support (I’ve attached a screenshot from Microsoft’s official lifecycle page for reference). I understand that C# 12 cannot be used with .NET Core 5/6, as those SDKs are tied to older Roslyn versions (C# 9 / C# 10 respectively). In contrast, .NET Framework (including 4.8 / 4.8.1 and even 3.5 SP1) is still in Active support according to Microsoft’s official lifecycle policy (see screenshot). This highlights an important distinction: Language version compatibility depends on the compiler (Roslyn), not the runtime. Actively supported .NET Framework versions can be built with modern C# (including C# 12) when using a current toolchain such as Visual Studio 2022. Older .NET Core versions (5/6) are out of support and therefore not a compatibility target, even though they technically cap the language version. Given that Mapster already requires C# 8+ semantics, targeting a modern compiler aligns better with actively supported platforms and avoids optimizing for deprecated SDKs. Happy to follow whatever direction you prefer here — just wanted to clarify the support-status angle. |
|
@asp2286 @DevTKSS
Perhaps the runtimes for these environments have already been updated, or in C#12 does not use anything that could cause a failure. 🤔 Because the warning for the latest version states the following:
and this
|
|
@asp2286 I don't know about this LangVersion compile time difference you are mentioning and I didn't found a official resource, with statement of Microsoft for example, about e.g. a @DocSvartz yes quite like your example, just I would prefer not to rename API maybe 🤔 But Backporting is in my opinion maybe the wrong wording? I mean I am not as deep into publishing packages, but assuming we are building a project and then pack it, when using the constants and not using LangVersion (directly or indirect through Or do we have any unknown constants for LangVersion I am not aware of, to avoid trying to bring net8.0 to net framework?🤔 So Its not about a decision like:
Then only providing the best for both worlds by:
|
|
@asp2286 @DevTKSS You can add the following: Then the other TFMs will use the LangVersion set for it. And in netstandard2.0, the manually set one 🤔 Or using a version that allows you to use Nullable reference type. To simply avoid rewriting the parts in which they are used |
@DevTKSS However, the same documentation mentions possible runtime issues, suggesting some kind of duality to this setting.🤔 |



Fixes #639
Why
The main
Mapsterpackage currently only targetsnet8.0+, which prevents consumers on .NET Framework 4.8 (and othernetstandard2.0-based targets) from upgrading.What changed
Mapstertonetstandard2.0(src/Mapster/Mapster.csproj).netstandard2.0(LINQExceptBy/IntersectBy, range indexing).RequiredMemberAttribute(string-based attribute check keeps behavior on newer TFMs while allowingnetstandard2.0compilation).IsExternalInitfornetstandard2.0.netstandard2.0-only references required for runtime code generation/dynamic binder (System.Reflection.Emit*,Microsoft.CSharp).Validation
dotnet build src/Mapster/Mapster.csproj -c Release -f netstandard2.0dotnet test src/Mapster.Tests/Mapster.Tests.csproj -c Release -f net8.0