Rename client bin dir to _bin so it can be served under default config
This commit is contained in:
parent
fb8a01a138
commit
9b95b68dbf
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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(),
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
@ -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)));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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<IHostingEnvironment>();
|
||||
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<string, string>
|
||||
{
|
||||
{ ".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)
|
||||
|
|
|
|||
Loading…
Reference in New Issue