From aa63da5151926c74a65b7ef54d4bdee1ac3dfc91 Mon Sep 17 00:00:00 2001 From: Steve Sanderson Date: Thu, 14 Dec 2017 11:59:55 +0000 Subject: [PATCH] Write out all client app files to disk at build time instead of serving dynamically at runtime --- Blazor.sln | 12 ++-- .../Microsoft.Blazor.Browser.csproj | 2 - .../Cli/Commands/BuildCommand.cs | 43 +++++++++++++ ...lled.cs => CheckNodeJsInstalledCommand.cs} | 2 +- .../Cli/Program.cs | 3 +- src/Microsoft.Blazor.BuildTools/Core/Build.cs | 25 ++++++++ .../Core/ClientFileSystem.cs | 44 ++++++++++++++ .../Core/FileUtil.cs | 60 +++++++++++++++++++ .../FrameworkFiles/FrameworkFileProvider.cs | 2 +- .../ReferencedAssemblyFileProvider.cs | 2 +- .../ReferencedAssemblyResolver.cs | 2 +- .../WebRootFiles/IndexHtmlFileProvider.cs | 2 +- .../Core}/WebRootFiles/WebRootFileProvider.cs | 2 +- .../Microsoft.Blazor.BuildTools.csproj | 5 ++ .../Properties/AssemblyInfo.cs | 3 + .../targets/All.targets | 10 ++++ .../BlazorAppBuilderExtensions.cs | 44 +++++--------- .../Microsoft.Blazor.Server.csproj | 7 --- .../Properties/AssemblyInfo.cs | 1 - .../IndexHtmlFileProviderTest.cs | 2 +- .../Microsoft.Blazor.Build.Test.csproj} | 2 +- .../ReferencedAssemblyFileProviderTest.cs | 2 +- .../Microsoft.Blazor.E2ETest.csproj | 2 + 23 files changed, 223 insertions(+), 56 deletions(-) create mode 100644 src/Microsoft.Blazor.BuildTools/Cli/Commands/BuildCommand.cs rename src/Microsoft.Blazor.BuildTools/Cli/Commands/{CheckNodeJsInstalled.cs => CheckNodeJsInstalledCommand.cs} (98%) create mode 100644 src/Microsoft.Blazor.BuildTools/Core/Build.cs create mode 100644 src/Microsoft.Blazor.BuildTools/Core/ClientFileSystem.cs create mode 100644 src/Microsoft.Blazor.BuildTools/Core/FileUtil.cs rename src/{Microsoft.Blazor.Server => Microsoft.Blazor.BuildTools/Core}/FrameworkFiles/FrameworkFileProvider.cs (95%) rename src/{Microsoft.Blazor.Server => Microsoft.Blazor.BuildTools/Core}/FrameworkFiles/ReferencedAssemblyFileProvider.cs (97%) rename src/{Microsoft.Blazor.Server => Microsoft.Blazor.BuildTools/Core}/FrameworkFiles/ReferencedAssemblyResolver.cs (97%) rename src/{Microsoft.Blazor.Server => Microsoft.Blazor.BuildTools/Core}/WebRootFiles/IndexHtmlFileProvider.cs (97%) rename src/{Microsoft.Blazor.Server => Microsoft.Blazor.BuildTools/Core}/WebRootFiles/WebRootFileProvider.cs (94%) create mode 100644 src/Microsoft.Blazor.BuildTools/Properties/AssemblyInfo.cs rename test/{Microsoft.Blazor.Server.Test => Microsoft.Blazor.Build.Test}/IndexHtmlFileProviderTest.cs (98%) rename test/{Microsoft.Blazor.Server.Test/Microsoft.Blazor.Server.Test.csproj => Microsoft.Blazor.Build.Test/Microsoft.Blazor.Build.Test.csproj} (84%) rename test/{Microsoft.Blazor.Server.Test => Microsoft.Blazor.Build.Test}/ReferencedAssemblyFileProviderTest.cs (98%) diff --git a/Blazor.sln b/Blazor.sln index f77ea75b01..bee8b920f5 100644 --- a/Blazor.sln +++ b/Blazor.sln @@ -48,7 +48,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Blazor.Common", " EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Blazor.Common.Test", "test\Microsoft.Blazor.Common.Test\Microsoft.Blazor.Common.Test.csproj", "{7F0BF3EA-6985-49F6-8070-0BBA41448BB0}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Blazor.Server.Test", "test\Microsoft.Blazor.Server.Test\Microsoft.Blazor.Server.Test.csproj", "{0F94DDDD-DAD3-43C6-AFB1-4FA21BABCD3B}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Blazor.Build.Test", "test\Microsoft.Blazor.Build.Test\Microsoft.Blazor.Build.Test.csproj", "{709C7EBE-EB93-4F6D-9491-D714B0D2E898}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -116,10 +116,10 @@ Global {7F0BF3EA-6985-49F6-8070-0BBA41448BB0}.Debug|Any CPU.Build.0 = Debug|Any CPU {7F0BF3EA-6985-49F6-8070-0BBA41448BB0}.Release|Any CPU.ActiveCfg = Release|Any CPU {7F0BF3EA-6985-49F6-8070-0BBA41448BB0}.Release|Any CPU.Build.0 = Release|Any CPU - {0F94DDDD-DAD3-43C6-AFB1-4FA21BABCD3B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {0F94DDDD-DAD3-43C6-AFB1-4FA21BABCD3B}.Debug|Any CPU.Build.0 = Debug|Any CPU - {0F94DDDD-DAD3-43C6-AFB1-4FA21BABCD3B}.Release|Any CPU.ActiveCfg = Release|Any CPU - {0F94DDDD-DAD3-43C6-AFB1-4FA21BABCD3B}.Release|Any CPU.Build.0 = Release|Any CPU + {709C7EBE-EB93-4F6D-9491-D714B0D2E898}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {709C7EBE-EB93-4F6D-9491-D714B0D2E898}.Debug|Any CPU.Build.0 = Debug|Any CPU + {709C7EBE-EB93-4F6D-9491-D714B0D2E898}.Release|Any CPU.ActiveCfg = Release|Any CPU + {709C7EBE-EB93-4F6D-9491-D714B0D2E898}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -143,7 +143,7 @@ Global {2A076721-6081-4517-8329-B9E5110D6DAC} = {F5FDD4E5-6A52-4A86-BE5E-5E42CB1DC8DA} {21EF76A4-63CC-455D-907C-F86C9E442CEC} = {B867E038-B3CE-43E3-9292-61568C46CDEB} {7F0BF3EA-6985-49F6-8070-0BBA41448BB0} = {ADA3AE29-F6DE-49F6-8C7C-B321508CAE8E} - {0F94DDDD-DAD3-43C6-AFB1-4FA21BABCD3B} = {ADA3AE29-F6DE-49F6-8C7C-B321508CAE8E} + {709C7EBE-EB93-4F6D-9491-D714B0D2E898} = {ADA3AE29-F6DE-49F6-8C7C-B321508CAE8E} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {504DA352-6788-4DC0-8705-82167E72A4D3} diff --git a/src/Microsoft.Blazor.Browser/Microsoft.Blazor.Browser.csproj b/src/Microsoft.Blazor.Browser/Microsoft.Blazor.Browser.csproj index 666d9f2cd8..54d4ef4e65 100644 --- a/src/Microsoft.Blazor.Browser/Microsoft.Blazor.Browser.csproj +++ b/src/Microsoft.Blazor.Browser/Microsoft.Blazor.Browser.csproj @@ -18,10 +18,8 @@ - - diff --git a/src/Microsoft.Blazor.BuildTools/Cli/Commands/BuildCommand.cs b/src/Microsoft.Blazor.BuildTools/Cli/Commands/BuildCommand.cs new file mode 100644 index 0000000000..f330df1c02 --- /dev/null +++ b/src/Microsoft.Blazor.BuildTools/Cli/Commands/BuildCommand.cs @@ -0,0 +1,43 @@ +// 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.BuildTools.Core; +using Microsoft.Extensions.CommandLineUtils; +using System; + +namespace Microsoft.Blazor.BuildTools.Cli.Commands +{ + internal class BuildCommand + { + public static void Command(CommandLineApplication command) + { + var clientAssemblyPath = command.Argument("assembly", + "Specifies the assembly for the Blazor application."); + var webRootPath = command.Option("--webroot", + "Specifies the path to the directory containing static files to be served", + CommandOptionType.SingleValue); + + command.OnExecute(() => + { + if (string.IsNullOrEmpty(clientAssemblyPath.Value)) + { + Console.WriteLine($"ERROR: No value specified for required argument '{clientAssemblyPath.Name}'."); + return 1; + } + + try + { + Console.WriteLine($"Building Blazor app from {clientAssemblyPath.Value}..."); + Build.Execute(clientAssemblyPath.Value, webRootPath.HasValue() ? webRootPath.Value() : null); + return 0; + } + catch (Exception ex) + { + Console.WriteLine($"ERROR: {ex.Message}"); + Console.WriteLine(ex.StackTrace); + return 1; + } + }); + } + } +} diff --git a/src/Microsoft.Blazor.BuildTools/Cli/Commands/CheckNodeJsInstalled.cs b/src/Microsoft.Blazor.BuildTools/Cli/Commands/CheckNodeJsInstalledCommand.cs similarity index 98% rename from src/Microsoft.Blazor.BuildTools/Cli/Commands/CheckNodeJsInstalled.cs rename to src/Microsoft.Blazor.BuildTools/Cli/Commands/CheckNodeJsInstalledCommand.cs index b2152d7623..cd613b3f1c 100644 --- a/src/Microsoft.Blazor.BuildTools/Cli/Commands/CheckNodeJsInstalled.cs +++ b/src/Microsoft.Blazor.BuildTools/Cli/Commands/CheckNodeJsInstalledCommand.cs @@ -8,7 +8,7 @@ using System.Text.RegularExpressions; namespace Microsoft.Blazor.BuildTools.Cli.Commands { - class CheckNodeJsInstalled + class CheckNodeJsInstalledCommand { private static Regex NodeVersionRegex = new Regex(@"^v(\d+\.\d+\.\d+)"); diff --git a/src/Microsoft.Blazor.BuildTools/Cli/Program.cs b/src/Microsoft.Blazor.BuildTools/Cli/Program.cs index 9c2f3e6beb..61402fdce9 100644 --- a/src/Microsoft.Blazor.BuildTools/Cli/Program.cs +++ b/src/Microsoft.Blazor.BuildTools/Cli/Program.cs @@ -16,7 +16,8 @@ namespace Microsoft.Blazor.BuildTools }; app.HelpOption("-?|-h|--help"); - app.Command("checknodejs", CheckNodeJsInstalled.Command); + app.Command("checknodejs", CheckNodeJsInstalledCommand.Command); + app.Command("build", BuildCommand.Command); if (args.Length > 0) { diff --git a/src/Microsoft.Blazor.BuildTools/Core/Build.cs b/src/Microsoft.Blazor.BuildTools/Core/Build.cs new file mode 100644 index 0000000000..faa7046755 --- /dev/null +++ b/src/Microsoft.Blazor.BuildTools/Core/Build.cs @@ -0,0 +1,25 @@ +// 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.IO; + +namespace Microsoft.Blazor.BuildTools.Core +{ + internal static class Build + { + internal static void Execute(string assemblyPath, string webRootPath) + { + var clientFileSystem = ClientFileSystem.Instantiate(assemblyPath, webRootPath); + var distDirPath = Path.Combine(Path.GetDirectoryName(assemblyPath), "dist"); + FileUtil.WriteFileProviderToDisk(clientFileSystem, distDirPath, clean: true); + + // Temporary hack until ClientFileSystem can mount the subdirs in the correct place + var frameworkPath = Path.Combine(distDirPath, "_framework"); + Directory.CreateDirectory(frameworkPath); + Directory.Move(Path.Combine(distDirPath, "_bin"), Path.Combine(frameworkPath, "_bin")); + Directory.Move(Path.Combine(distDirPath, "asmjs"), Path.Combine(frameworkPath, "asmjs")); + Directory.Move(Path.Combine(distDirPath, "wasm"), Path.Combine(frameworkPath, "wasm")); + File.Move(Path.Combine(distDirPath, "blazor.js"), Path.Combine(frameworkPath, "blazor.js")); + } + } +} diff --git a/src/Microsoft.Blazor.BuildTools/Core/ClientFileSystem.cs b/src/Microsoft.Blazor.BuildTools/Core/ClientFileSystem.cs new file mode 100644 index 0000000000..8b3787ebbe --- /dev/null +++ b/src/Microsoft.Blazor.BuildTools/Core/ClientFileSystem.cs @@ -0,0 +1,44 @@ +// 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.BuildTools.Core.FrameworkFiles; +using Microsoft.Blazor.BuildTools.Core.WebRootFiles; +using Microsoft.Extensions.FileProviders; +using System.Collections.Generic; +using System.IO; + +namespace Microsoft.Blazor.BuildTools.Core +{ + internal static class ClientFileSystem + { + public static IFileProvider Instantiate(string clientAssemblyPath, string webRootPath) + { + var fileProviders = new List(); + + if (!File.Exists(clientAssemblyPath)) + { + throw new FileNotFoundException($"Could not find client assembly file at '{clientAssemblyPath}'.", clientAssemblyPath); + } + + var frameworkFileProvider = FrameworkFileProvider.Instantiate( + clientAssemblyPath); + fileProviders.Add(frameworkFileProvider); + + if (!string.IsNullOrEmpty(webRootPath)) + { + if (!Directory.Exists(webRootPath)) + { + throw new DirectoryNotFoundException($"Could not find web root directory at '{webRootPath}'."); + } + + var webRootFileProvider = WebRootFileProvider.Instantiate( + webRootPath, + Path.GetFileNameWithoutExtension(clientAssemblyPath), + frameworkFileProvider.GetDirectoryContents("/_bin")); + fileProviders.Add(webRootFileProvider); + } + + return new CompositeFileProvider(fileProviders); + } + } +} diff --git a/src/Microsoft.Blazor.BuildTools/Core/FileUtil.cs b/src/Microsoft.Blazor.BuildTools/Core/FileUtil.cs new file mode 100644 index 0000000000..e85f8e5c2f --- /dev/null +++ b/src/Microsoft.Blazor.BuildTools/Core/FileUtil.cs @@ -0,0 +1,60 @@ +// 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.Extensions.FileProviders; +using System.IO; + +namespace Microsoft.Blazor.BuildTools.Core +{ + internal static class FileUtil + { + public static void WriteFileProviderToDisk(IFileProvider fileProvider, string outputDir, bool clean) + { + Directory.CreateDirectory(outputDir); + + if (clean) + { + CleanDirectory(outputDir); + } + + WriteFileProviderToDisk(fileProvider, string.Empty, outputDir); + } + + private static void WriteFileProviderToDisk(IFileProvider fileProvider, string subpath, string outputDir) + { + foreach (var item in fileProvider.GetDirectoryContents(subpath)) + { + var itemOutputPath = Path.Combine(outputDir, item.Name); + if (item.IsDirectory) + { + Directory.CreateDirectory(itemOutputPath); + WriteFileProviderToDisk(fileProvider, item.PhysicalPath, itemOutputPath); + } + else + { + using (var stream = item.CreateReadStream()) + using (var fileStream = File.Open(itemOutputPath, FileMode.Create)) + { + stream.CopyTo(fileStream); + } + } + } + } + + private static void CleanDirectory(string path) + { + foreach (var itemName in Directory.GetFileSystemEntries(path)) + { + var itemPath = Path.Combine(path, itemName); + if (File.GetAttributes(itemPath).HasFlag(FileAttributes.Directory)) + { + Directory.Delete(itemPath, recursive: true); + } + else + { + File.Delete(itemPath); + } + } + } + } +} diff --git a/src/Microsoft.Blazor.Server/FrameworkFiles/FrameworkFileProvider.cs b/src/Microsoft.Blazor.BuildTools/Core/FrameworkFiles/FrameworkFileProvider.cs similarity index 95% rename from src/Microsoft.Blazor.Server/FrameworkFiles/FrameworkFileProvider.cs rename to src/Microsoft.Blazor.BuildTools/Core/FrameworkFiles/FrameworkFileProvider.cs index aee39d5741..9b1bb945a9 100644 --- a/src/Microsoft.Blazor.Server/FrameworkFiles/FrameworkFileProvider.cs +++ b/src/Microsoft.Blazor.BuildTools/Core/FrameworkFiles/FrameworkFileProvider.cs @@ -6,7 +6,7 @@ using Microsoft.Blazor.Mono; using Microsoft.Extensions.FileProviders; using System.IO; -namespace Microsoft.Blazor.Server.FrameworkFiles +namespace Microsoft.Blazor.BuildTools.Core.FrameworkFiles { internal static class FrameworkFileProvider { diff --git a/src/Microsoft.Blazor.Server/FrameworkFiles/ReferencedAssemblyFileProvider.cs b/src/Microsoft.Blazor.BuildTools/Core/FrameworkFiles/ReferencedAssemblyFileProvider.cs similarity index 97% rename from src/Microsoft.Blazor.Server/FrameworkFiles/ReferencedAssemblyFileProvider.cs rename to src/Microsoft.Blazor.BuildTools/Core/FrameworkFiles/ReferencedAssemblyFileProvider.cs index f05bca0444..1b58dbeb7f 100644 --- a/src/Microsoft.Blazor.Server/FrameworkFiles/ReferencedAssemblyFileProvider.cs +++ b/src/Microsoft.Blazor.BuildTools/Core/FrameworkFiles/ReferencedAssemblyFileProvider.cs @@ -7,7 +7,7 @@ using System.Linq; using Mono.Cecil; using Microsoft.Blazor.Internal.Common.FileProviders; -namespace Microsoft.Blazor.Server.FrameworkFiles +namespace Microsoft.Blazor.BuildTools.Core.FrameworkFiles { internal class ReferencedAssemblyFileProvider : InMemoryFileProvider { diff --git a/src/Microsoft.Blazor.Server/FrameworkFiles/ReferencedAssemblyResolver.cs b/src/Microsoft.Blazor.BuildTools/Core/FrameworkFiles/ReferencedAssemblyResolver.cs similarity index 97% rename from src/Microsoft.Blazor.Server/FrameworkFiles/ReferencedAssemblyResolver.cs rename to src/Microsoft.Blazor.BuildTools/Core/FrameworkFiles/ReferencedAssemblyResolver.cs index 0d43c7d004..9c41cec629 100644 --- a/src/Microsoft.Blazor.Server/FrameworkFiles/ReferencedAssemblyResolver.cs +++ b/src/Microsoft.Blazor.BuildTools/Core/FrameworkFiles/ReferencedAssemblyResolver.cs @@ -5,7 +5,7 @@ using Microsoft.Extensions.FileProviders; using System.IO; using System.Linq; -namespace Microsoft.Blazor.Server.FrameworkFiles +namespace Microsoft.Blazor.BuildTools.Core.FrameworkFiles { internal class ReferencedAssemblyResolver { diff --git a/src/Microsoft.Blazor.Server/WebRootFiles/IndexHtmlFileProvider.cs b/src/Microsoft.Blazor.BuildTools/Core/WebRootFiles/IndexHtmlFileProvider.cs similarity index 97% rename from src/Microsoft.Blazor.Server/WebRootFiles/IndexHtmlFileProvider.cs rename to src/Microsoft.Blazor.BuildTools/Core/WebRootFiles/IndexHtmlFileProvider.cs index 7242811ff3..68762cf525 100644 --- a/src/Microsoft.Blazor.Server/WebRootFiles/IndexHtmlFileProvider.cs +++ b/src/Microsoft.Blazor.BuildTools/Core/WebRootFiles/IndexHtmlFileProvider.cs @@ -8,7 +8,7 @@ using System.Text; using Microsoft.Extensions.FileProviders; using System.Linq; -namespace Microsoft.Blazor.Server.WebRootFiles +namespace Microsoft.Blazor.BuildTools.Core.WebRootFiles { internal class IndexHtmlFileProvider : InMemoryFileProvider { diff --git a/src/Microsoft.Blazor.Server/WebRootFiles/WebRootFileProvider.cs b/src/Microsoft.Blazor.BuildTools/Core/WebRootFiles/WebRootFileProvider.cs similarity index 94% rename from src/Microsoft.Blazor.Server/WebRootFiles/WebRootFileProvider.cs rename to src/Microsoft.Blazor.BuildTools/Core/WebRootFiles/WebRootFileProvider.cs index 4c009609ab..c51ec40fbc 100644 --- a/src/Microsoft.Blazor.Server/WebRootFiles/WebRootFileProvider.cs +++ b/src/Microsoft.Blazor.BuildTools/Core/WebRootFiles/WebRootFileProvider.cs @@ -5,7 +5,7 @@ using Microsoft.Extensions.FileProviders; using System.Collections.Generic; using System.IO; -namespace Microsoft.Blazor.Server.WebRootFiles +namespace Microsoft.Blazor.BuildTools.Core.WebRootFiles { internal static class WebRootFileProvider { diff --git a/src/Microsoft.Blazor.BuildTools/Microsoft.Blazor.BuildTools.csproj b/src/Microsoft.Blazor.BuildTools/Microsoft.Blazor.BuildTools.csproj index c909827da6..b3a9d5b5bf 100644 --- a/src/Microsoft.Blazor.BuildTools/Microsoft.Blazor.BuildTools.csproj +++ b/src/Microsoft.Blazor.BuildTools/Microsoft.Blazor.BuildTools.csproj @@ -15,7 +15,12 @@ + + + + + diff --git a/src/Microsoft.Blazor.BuildTools/Properties/AssemblyInfo.cs b/src/Microsoft.Blazor.BuildTools/Properties/AssemblyInfo.cs new file mode 100644 index 0000000000..04a6cf1896 --- /dev/null +++ b/src/Microsoft.Blazor.BuildTools/Properties/AssemblyInfo.cs @@ -0,0 +1,3 @@ +using System.Runtime.CompilerServices; + +[assembly: InternalsVisibleTo("Microsoft.Blazor.Build.Test")] diff --git a/src/Microsoft.Blazor.BuildTools/targets/All.targets b/src/Microsoft.Blazor.BuildTools/targets/All.targets index 46b7f19d04..dfa1e51db3 100644 --- a/src/Microsoft.Blazor.BuildTools/targets/All.targets +++ b/src/Microsoft.Blazor.BuildTools/targets/All.targets @@ -14,4 +14,14 @@ + + + + wwwroot + $(ProjectDir)$(WebRootName) + --webroot $(WebRootPath) + + + + diff --git a/src/Microsoft.Blazor.Server/BlazorAppBuilderExtensions.cs b/src/Microsoft.Blazor.Server/BlazorAppBuilderExtensions.cs index eaacb4696c..1e082f3616 100644 --- a/src/Microsoft.Blazor.Server/BlazorAppBuilderExtensions.cs +++ b/src/Microsoft.Blazor.Server/BlazorAppBuilderExtensions.cs @@ -3,8 +3,7 @@ using Microsoft.AspNetCore.StaticFiles; using Microsoft.Blazor.Server; -using Microsoft.Blazor.Server.FrameworkFiles; -using Microsoft.Blazor.Server.WebRootFiles; +using Microsoft.Extensions.FileProviders; using System.Collections.Generic; using System.IO; using System.Net.Mime; @@ -21,7 +20,7 @@ namespace Microsoft.AspNetCore.Builder var clientAssemblyPath = Path.Combine(binDir, $"{clientAssemblyName}.dll"); applicationBuilder.UseBlazorInternal(clientAssemblyPath); } - + // TODO: Change this combination of APIs to make it possible to supply either // an assembly name (resolved to current bin dir) or full assembly path internal static void UseBlazorInternal( @@ -29,44 +28,29 @@ namespace Microsoft.AspNetCore.Builder string clientAssemblyPath) { var config = BlazorConfig.Read(clientAssemblyPath); - var frameworkFileProvider = FrameworkFileProvider.Instantiate( - config.SourceOutputAssemblyPath); + var clientAppBinDir = Path.GetDirectoryName(config.SourceOutputAssemblyPath); + var clientAppDistDir = Path.Combine(clientAppBinDir, "dist"); + var distFileProvider = new PhysicalFileProvider(clientAppDistDir); - if (config.WebRootPath != null) + applicationBuilder.UseDefaultFiles(new DefaultFilesOptions { - var webRootFileProvider = WebRootFileProvider.Instantiate( - config.WebRootPath, - Path.GetFileNameWithoutExtension(config.SourceOutputAssemblyPath), - frameworkFileProvider.GetDirectoryContents("/_bin")); + FileProvider = distFileProvider + }); - applicationBuilder.UseDefaultFiles(new DefaultFilesOptions - { - FileProvider = webRootFileProvider - }); - - applicationBuilder.UseStaticFiles(new StaticFileOptions - { - FileProvider = webRootFileProvider - }); - } - applicationBuilder.UseStaticFiles(new StaticFileOptions { - RequestPath = "/_framework", - FileProvider = frameworkFileProvider, + FileProvider = distFileProvider, ContentTypeProvider = CreateContentTypeProvider(), }); } private static IContentTypeProvider CreateContentTypeProvider() { - return new FileExtensionContentTypeProvider(new Dictionary - { - { ".dll", MediaTypeNames.Application.Octet }, - { ".js", "application/javascript" }, - { ".mem", MediaTypeNames.Application.Octet }, - { ".wasm", MediaTypeNames.Application.Octet }, - }); + var result = new FileExtensionContentTypeProvider(); + result.Mappings.Add(".dll", MediaTypeNames.Application.Octet); + result.Mappings.Add(".mem", MediaTypeNames.Application.Octet); + result.Mappings.Add(".wasm", MediaTypeNames.Application.Octet); + return result; } } } diff --git a/src/Microsoft.Blazor.Server/Microsoft.Blazor.Server.csproj b/src/Microsoft.Blazor.Server/Microsoft.Blazor.Server.csproj index 5609517a53..83548505e6 100644 --- a/src/Microsoft.Blazor.Server/Microsoft.Blazor.Server.csproj +++ b/src/Microsoft.Blazor.Server/Microsoft.Blazor.Server.csproj @@ -6,14 +6,7 @@ - - - - - - - diff --git a/src/Microsoft.Blazor.Server/Properties/AssemblyInfo.cs b/src/Microsoft.Blazor.Server/Properties/AssemblyInfo.cs index c41b478df6..026b371252 100644 --- a/src/Microsoft.Blazor.Server/Properties/AssemblyInfo.cs +++ b/src/Microsoft.Blazor.Server/Properties/AssemblyInfo.cs @@ -1,4 +1,3 @@ using System.Runtime.CompilerServices; [assembly: InternalsVisibleTo("Microsoft.Blazor.DevHost")] -[assembly: InternalsVisibleTo("Microsoft.Blazor.Server.Test")] diff --git a/test/Microsoft.Blazor.Server.Test/IndexHtmlFileProviderTest.cs b/test/Microsoft.Blazor.Build.Test/IndexHtmlFileProviderTest.cs similarity index 98% rename from test/Microsoft.Blazor.Server.Test/IndexHtmlFileProviderTest.cs rename to test/Microsoft.Blazor.Build.Test/IndexHtmlFileProviderTest.cs index 3015e15e41..afc28e9f92 100644 --- a/test/Microsoft.Blazor.Server.Test/IndexHtmlFileProviderTest.cs +++ b/test/Microsoft.Blazor.Build.Test/IndexHtmlFileProviderTest.cs @@ -1,13 +1,13 @@ // 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.Server.WebRootFiles; using Microsoft.Extensions.FileProviders; using System.IO; using System.Linq; using Xunit; using System; using AngleSharp.Parser.Html; +using Microsoft.Blazor.BuildTools.Core.WebRootFiles; namespace Microsoft.Blazor.Server.Test { diff --git a/test/Microsoft.Blazor.Server.Test/Microsoft.Blazor.Server.Test.csproj b/test/Microsoft.Blazor.Build.Test/Microsoft.Blazor.Build.Test.csproj similarity index 84% rename from test/Microsoft.Blazor.Server.Test/Microsoft.Blazor.Server.Test.csproj rename to test/Microsoft.Blazor.Build.Test/Microsoft.Blazor.Build.Test.csproj index 4667c107ff..7fba0b52cf 100644 --- a/test/Microsoft.Blazor.Server.Test/Microsoft.Blazor.Server.Test.csproj +++ b/test/Microsoft.Blazor.Build.Test/Microsoft.Blazor.Build.Test.csproj @@ -15,7 +15,7 @@ - + diff --git a/test/Microsoft.Blazor.Server.Test/ReferencedAssemblyFileProviderTest.cs b/test/Microsoft.Blazor.Build.Test/ReferencedAssemblyFileProviderTest.cs similarity index 98% rename from test/Microsoft.Blazor.Server.Test/ReferencedAssemblyFileProviderTest.cs rename to test/Microsoft.Blazor.Build.Test/ReferencedAssemblyFileProviderTest.cs index f421482f4c..759b41f439 100644 --- a/test/Microsoft.Blazor.Server.Test/ReferencedAssemblyFileProviderTest.cs +++ b/test/Microsoft.Blazor.Build.Test/ReferencedAssemblyFileProviderTest.cs @@ -1,8 +1,8 @@ // 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.BuildTools.Core.FrameworkFiles; using Microsoft.Blazor.Mono; -using Microsoft.Blazor.Server.FrameworkFiles; using Mono.Cecil; using System; using System.IO; diff --git a/test/Microsoft.Blazor.E2ETest/Microsoft.Blazor.E2ETest.csproj b/test/Microsoft.Blazor.E2ETest/Microsoft.Blazor.E2ETest.csproj index 14e05aa106..784b08ee34 100644 --- a/test/Microsoft.Blazor.E2ETest/Microsoft.Blazor.E2ETest.csproj +++ b/test/Microsoft.Blazor.E2ETest/Microsoft.Blazor.E2ETest.csproj @@ -16,7 +16,9 @@ + +