diff --git a/Microsoft.Blazor.Server.Test/ReferencedAssemblyFileProviderTest.cs b/Microsoft.Blazor.Server.Test/ReferencedAssemblyFileProviderTest.cs index 1360542924..7482f8dccb 100644 --- a/Microsoft.Blazor.Server.Test/ReferencedAssemblyFileProviderTest.cs +++ b/Microsoft.Blazor.Server.Test/ReferencedAssemblyFileProviderTest.cs @@ -23,7 +23,7 @@ namespace Microsoft.Blazor.Server.Test MonoStaticFileProvider.BclFiles); Assert.Collection(provider.GetDirectoryContents("/"), item => { - Assert.Equal("/bin", item.PhysicalPath); + Assert.Equal("/_bin", item.PhysicalPath); Assert.True(item.IsDirectory); }); } @@ -36,12 +36,12 @@ namespace Microsoft.Blazor.Server.Test entrypoint, entrypointData, MonoStaticFileProvider.BclFiles); - var contents = provider.GetDirectoryContents("/bin").OrderBy(i => i.Name).ToList(); + var contents = provider.GetDirectoryContents("/_bin").OrderBy(i => i.Name).ToList(); Assert.Collection(contents, - item => { Assert.Equal("/bin/mscorlib.dll", item.PhysicalPath); }, - item => { Assert.Equal("/bin/System.Core.dll", item.PhysicalPath); }, - item => { Assert.Equal("/bin/System.dll", item.PhysicalPath); }, - item => { Assert.Equal("/bin/System.Linq.Expressions.dll", item.PhysicalPath); }); + item => { Assert.Equal("/_bin/mscorlib.dll", item.PhysicalPath); }, + item => { Assert.Equal("/_bin/System.Core.dll", item.PhysicalPath); }, + item => { Assert.Equal("/_bin/System.dll", item.PhysicalPath); }, + item => { Assert.Equal("/_bin/System.Linq.Expressions.dll", item.PhysicalPath); }); } [Fact] @@ -71,26 +71,26 @@ namespace Microsoft.Blazor.Server.Test fewer assemblies from the server, and during publishing, illink would remove all the uncalled implementation code from mscorlib.dll anyway. */ - "/bin/Microsoft.Blazor.dll", - "/bin/mscorlib.dll", - "/bin/netstandard.dll", - "/bin/StandaloneApp.dll", - "/bin/System.Console.dll", - "/bin/System.Core.dll", - "/bin/System.Diagnostics.StackTrace.dll", - "/bin/System.dll", - "/bin/System.Globalization.Extensions.dll", - "/bin/System.Runtime.dll", - "/bin/System.Runtime.InteropServices.RuntimeInformation.dll", - "/bin/System.Runtime.Serialization.Primitives.dll", - "/bin/System.Runtime.Serialization.Xml.dll", - "/bin/System.Security.Cryptography.Algorithms.dll", - "/bin/System.Security.SecureString.dll", - "/bin/System.Xml.XPath.XDocument.dll", + "/_bin/Microsoft.Blazor.dll", + "/_bin/mscorlib.dll", + "/_bin/netstandard.dll", + "/_bin/StandaloneApp.dll", + "/_bin/System.Console.dll", + "/_bin/System.Core.dll", + "/_bin/System.Diagnostics.StackTrace.dll", + "/_bin/System.dll", + "/_bin/System.Globalization.Extensions.dll", + "/_bin/System.Runtime.dll", + "/_bin/System.Runtime.InteropServices.RuntimeInformation.dll", + "/_bin/System.Runtime.Serialization.Primitives.dll", + "/_bin/System.Runtime.Serialization.Xml.dll", + "/_bin/System.Security.Cryptography.Algorithms.dll", + "/_bin/System.Security.SecureString.dll", + "/_bin/System.Xml.XPath.XDocument.dll", }; // Act - var contents = provider.GetDirectoryContents("/bin") + var contents = provider.GetDirectoryContents("/_bin") .OrderBy(i => i.Name, StringComparer.InvariantCulture).ToList(); // Assert diff --git a/src/Microsoft.Blazor.Server/BlazorAppBuilderExtensions.cs b/src/Microsoft.Blazor.Server/BlazorAppBuilderExtensions.cs index 0b1627734b..67f6baf0f0 100644 --- a/src/Microsoft.Blazor.Server/BlazorAppBuilderExtensions.cs +++ b/src/Microsoft.Blazor.Server/BlazorAppBuilderExtensions.cs @@ -2,9 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.AspNetCore.StaticFiles; -using Microsoft.Blazor.Browser; -using Microsoft.Blazor.Mono; -using Microsoft.Extensions.FileProviders; +using Microsoft.Blazor.Server.ClientFilesystem; using System.Collections.Generic; using System.Net.Mime; @@ -17,9 +15,7 @@ namespace Microsoft.AspNetCore.Builder applicationBuilder.UseStaticFiles(new StaticFileOptions { RequestPath = "/_framework", - FileProvider = new CompositeFileProvider( - MonoStaticFileProvider.Instance, - BlazorBrowserFileProvider.Instance), + FileProvider = ClientFileProvider.Instantiate(), ContentTypeProvider = CreateContentTypeProvider(), }); } diff --git a/src/Microsoft.Blazor.Server/ClientFilesystem/ClientFileProvider.cs b/src/Microsoft.Blazor.Server/ClientFilesystem/ClientFileProvider.cs new file mode 100644 index 0000000000..3481a12f76 --- /dev/null +++ b/src/Microsoft.Blazor.Server/ClientFilesystem/ClientFileProvider.cs @@ -0,0 +1,18 @@ +// 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.Browser; +using Microsoft.Blazor.Mono; +using Microsoft.Extensions.FileProviders; + +namespace Microsoft.Blazor.Server.ClientFilesystem +{ + internal static class ClientFileProvider + { + public static IFileProvider Instantiate() + => new CompositeFileProvider( + MonoStaticFileProvider.JsFiles, + MonoStaticFileProvider.BclFiles, // TODO: Stop serving these, and serve the ReferencedAssemblyFileProvider instead + BlazorBrowserFileProvider.Instance); + } +} diff --git a/src/Microsoft.Blazor.Server/ClientFilesystem/ReferencedAssemblyFileProvider.cs b/src/Microsoft.Blazor.Server/ClientFilesystem/ReferencedAssemblyFileProvider.cs index 342c961f1d..6716138bf9 100644 --- a/src/Microsoft.Blazor.Server/ClientFilesystem/ReferencedAssemblyFileProvider.cs +++ b/src/Microsoft.Blazor.Server/ClientFilesystem/ReferencedAssemblyFileProvider.cs @@ -14,6 +14,8 @@ namespace Microsoft.Blazor.Server.ClientFilesystem { internal class ReferencedAssemblyFileProvider : InMemoryFileProvider { + private const string ClientBinDir = "_bin"; + public ReferencedAssemblyFileProvider(Assembly assembly, IFileProvider clientBcl) : this( AssemblyDefinition.ReadAssembly(assembly.Location), File.ReadAllBytes(assembly.Location), @@ -38,7 +40,7 @@ namespace Microsoft.Blazor.Server.ClientFilesystem AddWithReferencesRecursive(new ReferencedAssembly(entrypoint, entrypointData), clientBcl, foundAssemblies); return foundAssemblies.Values.Select(assembly => ( - $"/bin/{assembly.Name}.dll", + $"/{ClientBinDir}/{assembly.Name}.dll", (Stream)new MemoryStream(assembly.Data))); } diff --git a/src/Microsoft.Blazor.Server/DevelopmentServer/DevelopmentServerApplicationBuilderExtensions.cs b/src/Microsoft.Blazor.Server/DevelopmentServer/DevelopmentServerApplicationBuilderExtensions.cs index deb77eb205..623fafb972 100644 --- a/src/Microsoft.Blazor.Server/DevelopmentServer/DevelopmentServerApplicationBuilderExtensions.cs +++ b/src/Microsoft.Blazor.Server/DevelopmentServer/DevelopmentServerApplicationBuilderExtensions.cs @@ -2,13 +2,9 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.StaticFiles; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.FileProviders; -using System; -using System.Collections.Generic; using System.IO; -using System.Net.Mime; namespace Microsoft.AspNetCore.Builder { @@ -20,36 +16,7 @@ namespace Microsoft.AspNetCore.Builder { var env = applicationBuilder.ApplicationServices.GetRequiredService(); var sourcePath = Path.Combine(env.ContentRootPath, relativeSourcePath); - ServeWebRoot(applicationBuilder, sourcePath); - ServeClientBinDir(applicationBuilder, sourcePath); - } - - private static void ServeClientBinDir(IApplicationBuilder applicationBuilder, string clientAppSourceRoot) - { - var clientBinDirPath = FindClientBinDir(clientAppSourceRoot); - applicationBuilder.UseStaticFiles(new StaticFileOptions - { - RequestPath = "/_bin", - FileProvider = new PhysicalFileProvider(clientBinDirPath), - ContentTypeProvider = new FileExtensionContentTypeProvider(new Dictionary - { - { ".dll", MediaTypeNames.Application.Octet }, - }) - }); - } - - private static string FindClientBinDir(string clientAppSourceRoot) - { - var binDebugDir = Path.Combine(clientAppSourceRoot, "bin", "Debug"); - var subdirectories = Directory.GetDirectories(binDebugDir); - if (subdirectories.Length != 1) - { - throw new InvalidOperationException($"Could not locate bin directory for Blazor app. " + - $"Expected to find exactly 1 subdirectory in '{binDebugDir}', but found {subdirectories.Length}."); - } - - return Path.Combine(binDebugDir, subdirectories[0]); } private static void ServeWebRoot(IApplicationBuilder applicationBuilder, string clientAppSourceRoot)