From 9a57ccaf89feee76e96c60742d18f206c20e6a9e Mon Sep 17 00:00:00 2001 From: Luke Latham Date: Thu, 17 Sep 2020 05:21:50 -0500 Subject: [PATCH] Blazor WASM browser compatibility analyzer (#19904) --- .../blazor/components/class-libraries.md | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/aspnetcore/blazor/components/class-libraries.md b/aspnetcore/blazor/components/class-libraries.md index 2cb246d542..3365f83f62 100644 --- a/aspnetcore/blazor/components/class-libraries.md +++ b/aspnetcore/blazor/components/class-libraries.md @@ -155,6 +155,34 @@ An RCL can include static assets. The static assets are available to any app tha For more information, see . +::: moniker range=">= aspnetcore-5.0" + +## Browser compatibility analyzer for Blazor WebAssembly + +Blazor WebAssembly apps target the full .NET API surface area, but not all .NET APIs are supported on WebAssembly due to browser sandbox constraints. Unsupported APIs throw when running on WebAssembly. A platform compatibility analyzer warns the developer when the app uses APIs that aren't supported by the app's target platforms. For Blazor WebAssembly apps, this means checking that APIs are supported in browsers. Annotating .NET framework APIs for the compatibility analyzer is an on-going process, so not all .NET framework API is currently annotated. + +Blazor WebAssembly and Razor class library projects *automatically* enable browser compatibilty checks by adding `browser` as a supported platform with the `SupportedPlatform` MSBuild item. Library developers can manually add the `SupportedPlatform` item to a library's project file to enable the feature: + +```xml + + + +``` + +When authoring a library, indicate that a particular API isn't supported in browsers by specifying `browser` to : + +```csharp +[UnsupportedOSPlatform("browser")] +private static string GetLoggingDirectory() +{ + ... +} +``` + +For more information, see [Annotating APIs as unsupported on specific platforms (dotnet/designs GitHub repository](https://github.com/dotnet/designs/blob/main/accepted/2020/platform-exclusion/platform-exclusion.md#build-configuration-for-platforms). + +::: moniker-end + ## Build, pack, and ship to NuGet Because component libraries are standard .NET libraries, packaging and shipping them to NuGet is no different from packaging and shipping any library to NuGet. Packaging is performed using the [`dotnet pack`](/dotnet/core/tools/dotnet-pack) command in a command shell: