Skip to content

Commit 2d5da9c

Browse files
authored
Remove WebView dependency to AspNetCore.App (#31071)
The Blazor Desktop project must not depend on Microsoft.AspNetCore.App because it needs to run on almost any platform, including Android/iOS. But AspNetCore.App doesn't run on those platforms. This changes WebView to not use any packages that are part of AspNetCore.App, such as StaticFiles and Http.Abstractions. Instead, it has copies of those files.
1 parent 30e468e commit 2d5da9c

9 files changed

+1483
-4
lines changed

src/Components/WebView/WebView/src/FileExtensionContentTypeProvider.cs

Lines changed: 473 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
// NOTE: This file is copied from src/Middleware/StaticFiles/src/FileExtensionContentTypeProvider.cs
5+
// and made internal with a namespace change.
6+
// It can't be referenced directly from the StaticFiles package because that would cause this package to require
7+
// Microsoft.AspNetCore.App, thus preventing it from being used anywhere ASP.NET Core isn't supported (such as
8+
// various platforms that .NET MAUI runs on, such as Android and iOS).
9+
10+
using System.Diagnostics.CodeAnalysis;
11+
12+
namespace Microsoft.AspNetCore.Components.WebView
13+
{
14+
/// <summary>
15+
/// Used to look up MIME types given a file path
16+
/// </summary>
17+
internal interface IContentTypeProvider
18+
{
19+
/// <summary>
20+
/// Given a file path, determine the MIME type
21+
/// </summary>
22+
/// <param name="subpath">A file path</param>
23+
/// <param name="contentType">The resulting MIME type</param>
24+
/// <returns>True if MIME type could be determined</returns>
25+
bool TryGetContentType(string subpath, [MaybeNullWhen(false)] out string contentType);
26+
}
27+
}

src/Components/WebView/WebView/src/Microsoft.AspNetCore.Components.WebView.csproj

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
44
<TargetFramework>$(DefaultNetCoreTargetFramework)</TargetFramework>
@@ -28,7 +28,6 @@
2828

2929
<ItemGroup>
3030
<Reference Include="Microsoft.AspNetCore.Components.Web" />
31-
<Reference Include="Microsoft.AspNetCore.StaticFiles" />
3231
<Reference Include="Microsoft.Extensions.Configuration.Json" />
3332
<Reference Include="Microsoft.Extensions.Configuration.Binder" />
3433
<Reference Include="Microsoft.Extensions.FileProviders.Embedded" />

0 commit comments

Comments
 (0)