diff --git a/Blazor.sln b/Blazor.sln index c28a955771..9f41bc1bb6 100644 --- a/Blazor.sln +++ b/Blazor.sln @@ -32,7 +32,13 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Blazor.DevHost", EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BlazorStandalone", "samples\BlazorStandalone\BlazorStandalone.csproj", "{754BBACA-E05B-4DAE-ACFC-1B3B429AE43F}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.Blazor.BuildTools", "src\Microsoft.Blazor.BuildTools\Microsoft.Blazor.BuildTools.csproj", "{BB34336F-E68E-4411-9805-CAAA919F5EA1}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Blazor.BuildTools", "src\Microsoft.Blazor.BuildTools\Microsoft.Blazor.BuildTools.csproj", "{BB34336F-E68E-4411-9805-CAAA919F5EA1}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "HostedInAspNet", "HostedInAspNet", "{4D367450-96E9-4C8C-8B56-EED8ADE3A20D}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HostedInAspNet.Client", "samples\HostedInAspNet.Client\HostedInAspNet.Client.csproj", "{B4335F7C-4E86-4559-821F-F1B1C75F5FAE}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HostedInAspNet.Server", "samples\HostedInAspNet.Server\HostedInAspNet.Server.csproj", "{F8996835-41F7-4663-91DF-3B5652ADC37D}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -80,6 +86,14 @@ Global {BB34336F-E68E-4411-9805-CAAA919F5EA1}.Debug|Any CPU.Build.0 = Debug|Any CPU {BB34336F-E68E-4411-9805-CAAA919F5EA1}.Release|Any CPU.ActiveCfg = Release|Any CPU {BB34336F-E68E-4411-9805-CAAA919F5EA1}.Release|Any CPU.Build.0 = Release|Any CPU + {B4335F7C-4E86-4559-821F-F1B1C75F5FAE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B4335F7C-4E86-4559-821F-F1B1C75F5FAE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B4335F7C-4E86-4559-821F-F1B1C75F5FAE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B4335F7C-4E86-4559-821F-F1B1C75F5FAE}.Release|Any CPU.Build.0 = Release|Any CPU + {F8996835-41F7-4663-91DF-3B5652ADC37D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F8996835-41F7-4663-91DF-3B5652ADC37D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F8996835-41F7-4663-91DF-3B5652ADC37D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F8996835-41F7-4663-91DF-3B5652ADC37D}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -96,6 +110,9 @@ Global {EE690312-2353-4DD0-9250-EE5EDAC6D4F7} = {B867E038-B3CE-43E3-9292-61568C46CDEB} {754BBACA-E05B-4DAE-ACFC-1B3B429AE43F} = {F5FDD4E5-6A52-4A86-BE5E-5E42CB1DC8DA} {BB34336F-E68E-4411-9805-CAAA919F5EA1} = {B867E038-B3CE-43E3-9292-61568C46CDEB} + {4D367450-96E9-4C8C-8B56-EED8ADE3A20D} = {F5FDD4E5-6A52-4A86-BE5E-5E42CB1DC8DA} + {B4335F7C-4E86-4559-821F-F1B1C75F5FAE} = {4D367450-96E9-4C8C-8B56-EED8ADE3A20D} + {F8996835-41F7-4663-91DF-3B5652ADC37D} = {4D367450-96E9-4C8C-8B56-EED8ADE3A20D} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {504DA352-6788-4DC0-8705-82167E72A4D3} diff --git a/samples/HostedInAspNet.Client/HostedInAspNet.Client.csproj b/samples/HostedInAspNet.Client/HostedInAspNet.Client.csproj new file mode 100644 index 0000000000..b1f3487a93 --- /dev/null +++ b/samples/HostedInAspNet.Client/HostedInAspNet.Client.csproj @@ -0,0 +1,7 @@ + + + + netcoreapp2.0 + + + diff --git a/samples/HostedInAspNet.Client/Program.cs b/samples/HostedInAspNet.Client/Program.cs new file mode 100644 index 0000000000..bd6ec10054 --- /dev/null +++ b/samples/HostedInAspNet.Client/Program.cs @@ -0,0 +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 System; + +namespace HostedInAspNet.Client +{ + class Program + { + static void Main(string[] args) + { + Console.WriteLine("Hello World!"); + } + } +} diff --git a/samples/HostedInAspNet.Client/Properties/launchSettings.json b/samples/HostedInAspNet.Client/Properties/launchSettings.json new file mode 100644 index 0000000000..887df27891 --- /dev/null +++ b/samples/HostedInAspNet.Client/Properties/launchSettings.json @@ -0,0 +1,27 @@ +{ + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:56433/", + "sslPort": 0 + } + }, + "profiles": { + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "HostedInAspNet.Client": { + "commandName": "Project", + "launchBrowser": true, + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "applicationUrl": "http://localhost:56434/" + } + } +} \ No newline at end of file diff --git a/samples/HostedInAspNet.Client/wwwroot/index.html b/samples/HostedInAspNet.Client/wwwroot/index.html new file mode 100644 index 0000000000..d42bd98d14 --- /dev/null +++ b/samples/HostedInAspNet.Client/wwwroot/index.html @@ -0,0 +1,11 @@ + + + + + Sample Blazor app + + +

Hello

+ + + diff --git a/samples/HostedInAspNet.Server/HostedInAspNet.Server.csproj b/samples/HostedInAspNet.Server/HostedInAspNet.Server.csproj new file mode 100644 index 0000000000..8de9dad273 --- /dev/null +++ b/samples/HostedInAspNet.Server/HostedInAspNet.Server.csproj @@ -0,0 +1,16 @@ + + + + netcoreapp2.0 + + + + + + + + + + + + diff --git a/samples/HostedInAspNet.Server/Program.cs b/samples/HostedInAspNet.Server/Program.cs new file mode 100644 index 0000000000..9ca394d0f2 --- /dev/null +++ b/samples/HostedInAspNet.Server/Program.cs @@ -0,0 +1,21 @@ +// 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.AspNetCore; +using Microsoft.AspNetCore.Hosting; + +namespace HostedInAspNet.Server +{ + public class Program + { + public static void Main(string[] args) + { + BuildWebHost(args).Run(); + } + + public static IWebHost BuildWebHost(string[] args) => + WebHost.CreateDefaultBuilder(args) + .UseStartup() + .Build(); + } +} diff --git a/samples/HostedInAspNet.Server/Properties/launchSettings.json b/samples/HostedInAspNet.Server/Properties/launchSettings.json new file mode 100644 index 0000000000..2d087e9754 --- /dev/null +++ b/samples/HostedInAspNet.Server/Properties/launchSettings.json @@ -0,0 +1,27 @@ +{ + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:56484/", + "sslPort": 0 + } + }, + "profiles": { + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "HostedInAspNet.Server": { + "commandName": "Project", + "launchBrowser": true, + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "applicationUrl": "http://localhost:56485/" + } + } +} diff --git a/samples/HostedInAspNet.Server/Startup.cs b/samples/HostedInAspNet.Server/Startup.cs new file mode 100644 index 0000000000..bea85f7bed --- /dev/null +++ b/samples/HostedInAspNet.Server/Startup.cs @@ -0,0 +1,31 @@ +// 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; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.DependencyInjection; + +namespace HostedInAspNet.Server +{ + public class Startup + { + // This method gets called by the runtime. Use this method to add services to the container. + // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 + public void ConfigureServices(IServiceCollection services) + { + } + + // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. + public void Configure(IApplicationBuilder app, IHostingEnvironment env) + { + if (env.IsDevelopment()) + { + app.UseDeveloperExceptionPage(); + app.UseBlazorDevelopmentServer("../HostedInAspNet.Client"); + } + + app.UseBlazor(); + } + } +} diff --git a/src/Microsoft.Blazor.DevHost/Server/Startup.cs b/src/Microsoft.Blazor.DevHost/Server/Startup.cs index fb87f18fc4..80323c395c 100644 --- a/src/Microsoft.Blazor.DevHost/Server/Startup.cs +++ b/src/Microsoft.Blazor.DevHost/Server/Startup.cs @@ -16,8 +16,7 @@ namespace Microsoft.Blazor.DevHost.Server public void Configure(IApplicationBuilder app) { app.UseDeveloperExceptionPage(); - app.UseDefaultFiles(); - app.UseStaticFiles(); + app.UseBlazorDevelopmentServer("."); app.UseBlazor(); } } diff --git a/src/Microsoft.Blazor.Server/DevelopmentServer/DevelopmentServerApplicationBuilderExtensions.cs b/src/Microsoft.Blazor.Server/DevelopmentServer/DevelopmentServerApplicationBuilderExtensions.cs new file mode 100644 index 0000000000..2d45e544c8 --- /dev/null +++ b/src/Microsoft.Blazor.Server/DevelopmentServer/DevelopmentServerApplicationBuilderExtensions.cs @@ -0,0 +1,39 @@ +// 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.AspNetCore.Hosting; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.FileProviders; +using System.IO; + +namespace Microsoft.AspNetCore.Builder +{ + public static class DevelopmentServerApplicationBuilderExtensions + { + public static void UseBlazorDevelopmentServer( + this IApplicationBuilder applicationBuilder, + string relativeSourcePath) + { + var env = applicationBuilder.ApplicationServices.GetRequiredService(); + var sourcePath = Path.Combine(env.ContentRootPath, relativeSourcePath); + + ServeWebRoot(applicationBuilder, sourcePath); + } + + private static void ServeWebRoot(IApplicationBuilder applicationBuilder, string sourcePath) + { + var webRootFileProvider = new PhysicalFileProvider( + Path.Combine(sourcePath, "wwwroot")); + + applicationBuilder.UseDefaultFiles(new DefaultFilesOptions + { + FileProvider = webRootFileProvider + }); + + applicationBuilder.UseStaticFiles(new StaticFileOptions + { + FileProvider = webRootFileProvider + }); + } + } +} diff --git a/src/Microsoft.Blazor.Server/Microsoft.Blazor.Server.csproj b/src/Microsoft.Blazor.Server/Microsoft.Blazor.Server.csproj index b451283f02..f57984dbac 100644 --- a/src/Microsoft.Blazor.Server/Microsoft.Blazor.Server.csproj +++ b/src/Microsoft.Blazor.Server/Microsoft.Blazor.Server.csproj @@ -7,6 +7,7 @@ +