You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/standard/library-guidance/cross-platform-targeting.md
+16-9Lines changed: 16 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,19 +1,26 @@
1
1
---
2
2
title: Cross-platform targeting for .NET libraries
3
3
description: Best practice recommendations for creating cross-platform .NET libraries.
4
-
ms.date: 11/11/2024
4
+
ms.date: 08/20/2025
5
5
---
6
6
7
7
# Cross-platform targeting
8
8
9
9
Modern .NET supports multiple operating systems and devices. It's important for .NET open-source libraries to support as many developers as possible, whether they're building an ASP.NET website hosted in Azure, or a .NET game in Unity.
10
10
11
+
When choosing target frameworks for your library, it's important to distinguish between two different goals:
12
+
13
+
-**Modern APIs and patterns**: Your library leans into the benefits of the recent versions of the .NET platform. You use modern language patterns and support advanced deployment models like Native Ahead-of-Time compilation on the CoreCLR.
14
+
-**Breadth targeting**: Your library supports a wide range of .NET implementations and versions to maximize compatibility across different user scenarios.
15
+
16
+
These goals don't always require the same approach. If your target applications all use modern .NET, your libraries can target the same modern .NET versions without needing to target older frameworks.
17
+
11
18
## .NET and .NET Standard targets
12
19
13
20
.NET and .NET Standard targets are the best way to add cross-platform support to a .NET library.
14
21
22
+
* .NET versions 5 through 10 are implementations of .NET. Each version is a single product with a uniform set of capabilities and APIs that can be used for Windows desktop apps and cross-platform console apps, cloud services, and websites.
15
23
*[.NET Standard](../net-standard.md) is a specification of .NET APIs that are available on all .NET implementations. Targeting .NET Standard lets you produce libraries that are constrained to use APIs that are in a given version of .NET Standard, which means it's usable by all platforms that implement that version of .NET Standard.
16
-
* .NET 6-8 are implementations of .NET. Each version is a single product with a uniform set of capabilities and APIs that can be used for Windows desktop apps and cross-platform console apps, cloud services, and websites.
17
24
18
25
For more information about how .NET compares to .NET Standard, see [.NET 5 and .NET Standard](../net-standard.md#net-5-and-net-standard).
19
26
@@ -27,13 +34,13 @@ If your project targets .NET or .NET Standard and compiles successfully, it does
27
34
> [!TIP]
28
35
> The .NET team offers a [Platform compatibility analyzer](../analyzers/platform-compat-analyzer.md) to help you discover possible issues.
29
36
30
-
✔️ DO start with including a `netstandard2.0` target.
37
+
✔️ DO start with including a `net8.0` target or later for new libraries.
31
38
32
-
> Most general-purpose libraries don't need APIs outside of .NET Standard 2.0. .NET Standard 2.0 is supported by all modern platforms and is the recommended way to support multiple platforms with one target. If you don't need to support .NET Framework, you could also target .NET Standard 2.1.
39
+
> For new libraries, targeting modern .NET (such as .NET 8 or later) provides access to the latest APIs and performance improvements, and enables features like AOT and trimming. Modern .NET versions are cross-platform and provide excellent compatibility across Windows, Linux, and macOS.
33
40
34
-
✔️ DO include a `net6.0` target or later if you require new APIs introduced in a modern .NET.
41
+
✔️ CONSIDER including a `netstandard2.0` target if you need broad compatibility or .NET Framework support.
35
42
36
-
> .NET 6 and later apps can use a `netstandard2.0` target, so `net6.0` isn't required. You should explicitly target `net6.0`, `net7.0`, `net8.0`, or `net9.0`when you want to use newer .NET APIs.
43
+
> .NET Standard 2.0 is supported by .NET Framework 4.6.1+ and all modern .NET implementations. Include this target when you need to support .NET Framework applications or when building libraries for maximum compatibility across different .NET ecosystems.
37
44
38
45
❌ AVOID including a `netstandard1.x` target.
39
46
@@ -104,7 +111,7 @@ public static class GpsLocation
104
111
105
112
> The .NET Standard assembly will automatically be used by NuGet. Targeting individual .NET implementations increases the `*.nupkg` size for no benefit.
106
113
107
-
✔️ CONSIDER adding a target for `net462` when you're offering a`netstandard2.0` target.
114
+
✔️ CONSIDER adding a target for `net462` when you're also targeting`netstandard2.0`.
108
115
109
116
> Using .NET Standard 2.0 from .NET Framework has some issues that were addressed in .NET Framework 4.7.2. You can improve the experience for developers that are still on .NET Framework 4.6.2 - 4.7.1 by offering them a binary that's built for .NET Framework 4.6.2.
110
117
@@ -117,8 +124,8 @@ public static class GpsLocation
117
124
```xml
118
125
<ProjectSdk="Microsoft.NET.Sdk">
119
126
<PropertyGroup>
120
-
<!-- This project will output netstandard2.0 and net462 assemblies -->
0 commit comments