diff --git a/src/Microsoft.Blazor.Browser/BlazorBrowserFileProvider.cs b/src/Microsoft.Blazor.Browser/BlazorBrowserFileProvider.cs
index 1d6232020d..d1d65aef33 100644
--- a/src/Microsoft.Blazor.Browser/BlazorBrowserFileProvider.cs
+++ b/src/Microsoft.Blazor.Browser/BlazorBrowserFileProvider.cs
@@ -1,31 +1,15 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
+using Microsoft.Blazor.Internal.Common.FileProviders;
using Microsoft.Extensions.FileProviders;
-using Microsoft.Extensions.Primitives;
-using System;
namespace Microsoft.Blazor.Browser
{
- public class BlazorBrowserFileProvider : IFileProvider
+ public static class BlazorBrowserFileProvider
{
- private EmbeddedFileProvider _embeddedFiles = new EmbeddedFileProvider(
+ public static IFileProvider Instance = new EmbeddedResourceFileProvider(
typeof(BlazorBrowserFileProvider).Assembly,
- "blazor");
-
- public static BlazorBrowserFileProvider Instance = new BlazorBrowserFileProvider();
-
- private BlazorBrowserFileProvider()
- {
- }
-
- public IFileInfo GetFileInfo(string subpath)
- => _embeddedFiles.GetFileInfo(subpath.Replace('/', '$'));
-
- public IDirectoryContents GetDirectoryContents(string subpath)
- => throw new NotImplementedException(); // Don't need to support this
-
- public IChangeToken Watch(string filter)
- => throw new NotImplementedException(); // Don't need to support this
+ "blazor.");
}
}
diff --git a/src/Microsoft.Blazor.Browser/Microsoft.Blazor.Browser.csproj b/src/Microsoft.Blazor.Browser/Microsoft.Blazor.Browser.csproj
index 50d8c67d62..f506a70c31 100644
--- a/src/Microsoft.Blazor.Browser/Microsoft.Blazor.Browser.csproj
+++ b/src/Microsoft.Blazor.Browser/Microsoft.Blazor.Browser.csproj
@@ -17,6 +17,7 @@
+
@@ -30,7 +31,7 @@
-
+
diff --git a/src/Microsoft.Blazor.Common/FileProviders/EmbeddedResourceFileProvider.cs b/src/Microsoft.Blazor.Common/FileProviders/EmbeddedResourceFileProvider.cs
new file mode 100644
index 0000000000..eade32fefc
--- /dev/null
+++ b/src/Microsoft.Blazor.Common/FileProviders/EmbeddedResourceFileProvider.cs
@@ -0,0 +1,29 @@
+// Copyright (c) .NET Foundation. All rights reserved.
+// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
+
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Reflection;
+
+namespace Microsoft.Blazor.Internal.Common.FileProviders
+{
+ public class EmbeddedResourceFileProvider : InMemoryFileProvider
+ {
+ public EmbeddedResourceFileProvider(Assembly assembly, string resourceNamePrefix)
+ : base(ReadEmbeddedResources(assembly, resourceNamePrefix))
+ {
+ }
+
+ private static IEnumerable<(string, Stream)> ReadEmbeddedResources(
+ Assembly assembly, string resourceNamePrefix)
+ {
+ return assembly.GetManifestResourceNames()
+ .Where(name => name.StartsWith(resourceNamePrefix, StringComparison.Ordinal))
+ .Select(name => (
+ name.Substring(resourceNamePrefix.Length),
+ assembly.GetManifestResourceStream(name)));
+ }
+ }
+}
diff --git a/src/Microsoft.Blazor.Mono/Microsoft.Blazor.Mono.csproj b/src/Microsoft.Blazor.Mono/Microsoft.Blazor.Mono.csproj
index 3e4a232d78..3b49f08df2 100644
--- a/src/Microsoft.Blazor.Mono/Microsoft.Blazor.Mono.csproj
+++ b/src/Microsoft.Blazor.Mono/Microsoft.Blazor.Mono.csproj
@@ -7,14 +7,14 @@
-
+
- mono.$([System.String]::Copy('/%(RecursiveDir)%(FileName)%(Extension)').Replace('\', '$').Replace('/', '$'))
+ mono.$([System.String]::Copy('/%(RecursiveDir)%(FileName)%(Extension)').Replace('\', '/'))
diff --git a/src/Microsoft.Blazor.Mono/MonoStaticFileProvider.cs b/src/Microsoft.Blazor.Mono/MonoStaticFileProvider.cs
index 06f8505e87..de26ac6404 100644
--- a/src/Microsoft.Blazor.Mono/MonoStaticFileProvider.cs
+++ b/src/Microsoft.Blazor.Mono/MonoStaticFileProvider.cs
@@ -1,36 +1,14 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
+using Microsoft.Blazor.Internal.Common.FileProviders;
using Microsoft.Extensions.FileProviders;
-using Microsoft.Extensions.Primitives;
-using System;
namespace Microsoft.Blazor.Mono
{
- public class MonoStaticFileProvider : IFileProvider
+ public static class MonoStaticFileProvider
{
- private EmbeddedFileProvider _embeddedFiles = new EmbeddedFileProvider(
- typeof(MonoStaticFileProvider).Assembly,
- "mono");
-
- public static MonoStaticFileProvider Instance = new MonoStaticFileProvider();
-
- private MonoStaticFileProvider()
- {
- }
-
- public IFileInfo GetFileInfo(string subpath)
- {
- // EmbeddedFileProvider can't find resources whose names include '/' (or '\'),
- // so the resources in the assembly use '$' as a directory separator
- var possibleResourceName = subpath.Replace('/', '$');
- return _embeddedFiles.GetFileInfo(possibleResourceName);
- }
-
- public IDirectoryContents GetDirectoryContents(string subpath)
- => _embeddedFiles.GetDirectoryContents(subpath);
-
- public IChangeToken Watch(string filter)
- => throw new NotImplementedException(); // Don't need to support this
+ public readonly static IFileProvider Instance = new EmbeddedResourceFileProvider(
+ typeof(MonoStaticFileProvider).Assembly, "mono.");
}
}