Skip to content

Commit 29b0c67

Browse files
authored
Move preview APIs article to runtime libraries section of docs (#44436)
1 parent f255580 commit 29b0c67

File tree

9 files changed

+102
-96
lines changed

9 files changed

+102
-96
lines changed

.openpublishing.redirection.fundamentals.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
"source_path_from_root": "/docs/fundamentals/apicompat/package-validation/diagnostic-ids.md",
55
"redirect_url": "/dotnet/fundamentals/apicompat/diagnostic-ids"
66
},
7+
{
8+
"source_path_from_root": "/docs/fundamentals/apicompat/preview-apis.md",
9+
"redirect_url": "/dotnet/fundamentals/runtime-libraries/preview-apis"
10+
},
711
{
812
"source_path_from_root": "/docs/fundamentals/code-analysis/quality-rules/ca1071.md",
913
"redirect_url": "/dotnet/fundamentals/code-analysis/quality-rules/index"

docs/core/whats-new/dotnet-9/overview.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ For more information, see [What's new in the SDK for .NET 9](sdk.md).
7070
- Builds on top of `TensorPrimitives` for efficient math operations.
7171
- Provides efficient interop with AI libraries (ML.NET, TorchSharp, ONNX Runtime) using zero copies where possible.
7272
- Enables easy and efficient data manipulation with indexing and slicing operations.
73-
- Is [experimental](../../../fundamentals/apicompat/preview-apis.md#experimentalattribute) in .NET 9.
73+
- Is [experimental](../../../fundamentals/runtime-libraries/preview-apis.md#experimentalattribute) in .NET 9.
7474

7575
### ML.NET
7676

@@ -125,7 +125,7 @@ The focus of .NET Multi-platform App UI (.NET MAUI) in .NET 9 is enhanced perfor
125125
- <xref:Microsoft.Maui.Controls.Entry> now supports additional keyboard modes.
126126
- Control handlers automatically disconnect from their controls when possible.
127127
- <xref:Microsoft.Maui.Controls.Application.MainPage> is deprecated in favor of setting the primary page of the app by overriding <xref:Microsoft.Maui.Controls.Application.CreateWindow(Microsoft.Maui.IActivationState)?displayProperty=nameWithType> class.
128-
128+
129129
For more information about that these new features and more, see [What's new in .NET MAUI for .NET 9](/dotnet/maui/whats-new/dotnet-9).
130130

131131
## EF Core

docs/fundamentals/apicompat/preview-apis.md

Lines changed: 0 additions & 72 deletions
This file was deleted.
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
---
2+
title: Preview APIs
3+
description: Learn how to mark .NET APIs as preview.
4+
ms.date: 01/27/2025
5+
---
6+
7+
# Preview APIs
8+
9+
The .NET platform takes compatibility seriously. As such, the library ecosystem tends to avoid making breaking changes, especially with respect to the API.
10+
11+
Nonetheless, when designing APIs, it's important to be able to collect feedback from users and make changes to the API based on that feedback if necessary. To avoid surprises, you should understand which APIs you use are considered stable and which ones are still in active development and might change.
12+
13+
There are multiple ways an API can express that it's in preview form:
14+
15+
* The entire component is considered preview if it's exposed:
16+
17+
* In a preview release of the .NET runtime.
18+
* In a prerelease NuGet package.
19+
20+
* An otherwise stable component marks specific APIs as preview with the following attributes:
21+
22+
* <xref:System.Runtime.Versioning.RequiresPreviewFeaturesAttribute>
23+
* <xref:System.Diagnostics.CodeAnalysis.ExperimentalAttribute>
24+
25+
This article explains how each option works, and, for library developers, how to choose between these options.
26+
27+
## .NET runtime previews
28+
29+
With the exception of release candidates (RCs) with a go-live license, preview versions of the .NET runtime and SDK aren't supported.
30+
31+
As such, any APIs added as part of a .NET preview are considered subject to change, based on feedback the previews receive. To use a .NET runtime preview, you need to explicitly target a newer framework version in your project. By doing so, you implicitly express consent to consume APIs that might change.
32+
33+
## Prerelease NuGet packages
34+
35+
NuGet packages can either be stable or *prerelease*. Prerelease packages are marked as such with a prerelease suffix on their version. For example, `System.Text.Json 9.0.0-preview.2.24128.5` has a prerelease suffix of `preview.2.24128.5`.
36+
37+
Prerelease packages are commonly used as a means to collect feedback from early adopters. They are generally unsupported by their author.
38+
39+
When you install a package, either via the CLI or UI, you must explicitly indicate whether you want to install a prerelease version. By doing so, you implicitly express consent to consume APIs that might change.
40+
41+
## `RequiresPreviewFeaturesAttribute`
42+
43+
The <xref:System.Runtime.Versioning.RequiresPreviewFeaturesAttribute> attribute is used for APIs that require preview behaviors across the stack, including the runtime, the C# compiler, and libraries. When you consume APIs marked with this attribute, you'll receive a build error unless your project file includes the property `<EnablePreviewFeatures>true</EnablePreviewFeatures>`. Setting that property to `true` also sets `<LangVersion>Preview</LangVersion>`, which allows the use of preview language features.
44+
45+
As an example, in .NET 6 the *generic math* library was marked with <xref:System.Runtime.Versioning.RequiresPreviewFeaturesAttribute> because it required static interface members, which were in preview at the time.
46+
47+
## `ExperimentalAttribute`
48+
49+
.NET 8 added <xref:System.Diagnostics.CodeAnalysis.ExperimentalAttribute>, which doesn't require any runtime or language preview features and simply indicates that a given API isn't stable yet.
50+
51+
When building against an experimental API, the compiler produces an error. Each feature that's marked as experimental has its own separate diagnostic ID. To express consent to using an experimental API, you suppress the specific diagnostic. You can do that via any of the means for suppressing diagnostics, but the recommended way is to add the diagnostic to the project's `<NoWarn>` property.
52+
53+
Since each experimental feature has a separate ID, consenting to using one experimental feature doesn't consent to using another.
54+
55+
For more information, see [Experimental features][experimental-overview].
56+
57+
## Guidance for library developers
58+
59+
Library developers should generally express that an API is in preview in one of two ways:
60+
61+
* For new APIs introduced in a *prerelease* version of your package, you don't need to do anything; the package already expresses preview quality.
62+
* If you want to ship a stable package that contains some preview quality APIs, you should mark those APIs using `[Experimental]`. Make sure to use [your own diagnostic ID][choosing-diagnostic-ids] and make it specific to those features. If you have multiple independent features, consider using multiple IDs.
63+
64+
The `[RequiresPreviewFeatures]` attribute is only meant for components of the .NET platform itself. Even there, it's only used for APIs that require runtime and language preview features. If it's just an API that's in preview, the .NET platform uses the `[Experimental]` attribute.
65+
66+
The exception to this rule is if you're building a stable library and want to expose certain features that in turn depend on runtime or language preview behaviors. In that case, you should use `[RequiresPreviewFeatures]` for the entry points of that feature. However, you need to consider that users of such APIs have to turn on preview features too, which exposes them to all runtime, library, and language preview behaviors.
67+
68+
[choosing-diagnostic-ids]: ../../csharp/roslyn-sdk/choosing-diagnostic-ids.md
69+
[experimental-overview]: ../syslib-diagnostics/experimental-overview.md

docs/fundamentals/syslib-diagnostics/experimental-overview.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ Since each experimental feature has a separate ID, consenting to using one exper
1717

1818
The following table provides an index to the `SYSLIB5XXX` experimental APIs in .NET 9+.
1919

20-
| Diagnostic ID | Experimental version | Description |
21-
| - | - | - |
22-
| SYSLIB5001 | .NET 9 | <xref:System.Numerics.Tensors.Tensor%601> and related APIs in <xref:System.Numerics.Tensors> are experimental |
23-
| SYSLIB5002 | .NET 9 | <xref:System.Drawing.SystemColors> alternate colors are experimental |
24-
| [SYSLIB5003](./syslib5003.md) | .NET 9 | <xref:System.Runtime.Intrinsics.Arm.Sve> is experimental |
25-
| SYSLIB5004 | .NET 9 | <xref:System.Runtime.Intrinsics.X86.X86Base.DivRem(System.UInt32,System.Int32,System.Int32)> is experimental since performance is not as optimized as `T.DivRem` |
26-
| SYSLIB5005 | .NET 9 | <xref:System.Formats.Nrbf> is experimental |
20+
| Diagnostic ID | Experimental version | Description |
21+
|-------------------------------|----------------------|----------------------------------------------------------------------|
22+
| SYSLIB5001 | .NET 9 | <xref:System.Numerics.Tensors.Tensor%601> and related APIs in <xref:System.Numerics.Tensors> are experimental |
23+
| SYSLIB5002 | .NET 9 | <xref:System.Drawing.SystemColors> alternate colors are experimental |
24+
| [SYSLIB5003](./syslib5003.md) | .NET 9 | <xref:System.Runtime.Intrinsics.Arm.Sve> is experimental |
25+
| SYSLIB5004 | .NET 9 | <xref:System.Runtime.Intrinsics.X86.X86Base.DivRem(System.UInt32,System.Int32,System.Int32)> is experimental since performance is not as optimized as `T.DivRem` |
26+
| SYSLIB5005 | .NET 9 | <xref:System.Formats.Nrbf> is experimental |
2727

2828
## Suppress warnings
2929

@@ -61,4 +61,4 @@ To suppress the warnings in code:
6161

6262
## See also
6363

64-
- [Preview APIs](../apicompat/preview-apis.md)
64+
- [Preview APIs](../runtime-libraries/preview-apis.md)

docs/fundamentals/toc.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,8 @@ items:
540540
items:
541541
- name: Overview
542542
href: ../standard/runtime-libraries-overview.md
543+
- name: Preview APIs
544+
href: runtime-libraries/preview-apis.md
543545
- name: Format numbers, dates, other types
544546
items:
545547
- name: Overview

docs/navigate/tools-diagnostics/toc.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1929,8 +1929,6 @@ items:
19291929
- name: Overview
19301930
href: ../../fundamentals/apicompat/overview.md
19311931
displayName: api compatibility,apicompat
1932-
- name: Preview APIs
1933-
href: ../../fundamentals/apicompat/preview-apis.md
19341932
- name: Diagnostic IDs
19351933
href: ../../fundamentals/apicompat/diagnostic-ids.md
19361934
- name: Assembly validation

docs/standard/library-guidance/nuget.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,20 +65,20 @@ A NuGet package supports many [metadata properties](/nuget/reference/nuspec). Th
6565

6666
> Source Link automatically adds `RepositoryUrl` and `RepositoryType` metadata to the NuGet package. Source Link also adds information about the exact source code the package was built from. For example, a package created from a Git repository will have the commit hash added as metadata.
6767
68-
## Pre-release packages
68+
## Prerelease packages
6969

70-
NuGet packages with a version suffix are considered [pre-release](/nuget/create-packages/prerelease-packages). By default, the NuGet Package Manager UI shows stable releases unless a user opts-in to pre-release packages, making pre-release packages ideal for limited user testing.
70+
NuGet packages with a version suffix are considered [prerelease](/nuget/create-packages/prerelease-packages). By default, the NuGet Package Manager UI shows stable releases unless a user opts-in to prerelease packages, making prerelease packages ideal for limited user testing.
7171

7272
```xml
7373
<PackageVersion>1.0.1-beta1</PackageVersion>
7474
```
7575

7676
> [!NOTE]
77-
> A stable package cannot depend on a pre-release package. You must either make your own package pre-release or depend on an older stable version.
77+
> A stable package cannot depend on a prerelease package. You must either make your own package prerelease or depend on an older stable version.
7878
79-
![NuGet pre-release package dependency](./media/nuget/nuget-prerelease-package.png "NuGet pre-release package dependency")
79+
![NuGet prerelease package dependency](./media/nuget/nuget-prerelease-package.png "NuGet prerelease package dependency")
8080

81-
✔️ DO publish a pre-release package when testing, previewing, or experimenting.
81+
✔️ DO publish a prerelease package when testing, previewing, or experimenting.
8282

8383
✔️ DO publish a stable package when it's ready so other stable packages can reference it.
8484

0 commit comments

Comments
 (0)