diff --git a/samples/HostedInAspNet.Server/HostedInAspNet.Server.csproj b/samples/HostedInAspNet.Server/HostedInAspNet.Server.csproj
index 7c7f6fcda4..4cc06e7c02 100644
--- a/samples/HostedInAspNet.Server/HostedInAspNet.Server.csproj
+++ b/samples/HostedInAspNet.Server/HostedInAspNet.Server.csproj
@@ -10,7 +10,7 @@
-
+
diff --git a/samples/HostedInAspNet.Server/Startup.cs b/samples/HostedInAspNet.Server/Startup.cs
index c8f4237729..24ed5919ce 100644
--- a/samples/HostedInAspNet.Server/Startup.cs
+++ b/samples/HostedInAspNet.Server/Startup.cs
@@ -24,9 +24,7 @@ namespace HostedInAspNet.Server
app.UseDeveloperExceptionPage();
}
- app.UseBlazor(
- assemblyPath: typeof(Client.Program).Assembly.Location,
- staticFilesRoot: "../HostedInAspNet.Client/wwwroot");
+ app.UseBlazor("HostedInAspNet.Client");
}
}
}
diff --git a/samples/MonoSanity/MonoSanity.csproj b/samples/MonoSanity/MonoSanity.csproj
index ede1b64e7b..5fceb10e64 100644
--- a/samples/MonoSanity/MonoSanity.csproj
+++ b/samples/MonoSanity/MonoSanity.csproj
@@ -10,7 +10,7 @@
-
+
diff --git a/samples/MonoSanity/Startup.cs b/samples/MonoSanity/Startup.cs
index 78b3751565..68d05ca3ae 100644
--- a/samples/MonoSanity/Startup.cs
+++ b/samples/MonoSanity/Startup.cs
@@ -12,9 +12,7 @@ namespace MonoSanity
{
app.UseDeveloperExceptionPage();
app.UseFileServer(new FileServerOptions { EnableDefaultFiles = true });
- app.UseBlazor(
- assemblyPath: typeof(MonoSanityClient.Examples).Assembly.Location,
- staticFilesRoot: null);
+ app.UseBlazor("MonoSanityClient");
}
}
}
diff --git a/src/Microsoft.Blazor.DevHost/Server/Startup.cs b/src/Microsoft.Blazor.DevHost/Server/Startup.cs
index 4a4c664162..83e1d5b10b 100644
--- a/src/Microsoft.Blazor.DevHost/Server/Startup.cs
+++ b/src/Microsoft.Blazor.DevHost/Server/Startup.cs
@@ -20,12 +20,12 @@ namespace Microsoft.Blazor.DevHost.Server
public void Configure(IApplicationBuilder app)
{
app.UseDeveloperExceptionPage();
- app.UseBlazor(
- assemblyPath: FindClientAssembly(app).Location,
- staticFilesRoot: "wwwroot");
+
+ var clientAssemblyPath = FindClientAssemblyPath(app);
+ app.UseBlazorInternal(clientAssemblyPath);
}
- private static Assembly FindClientAssembly(IApplicationBuilder app)
+ private static string FindClientAssemblyPath(IApplicationBuilder app)
{
var env = app.ApplicationServices.GetRequiredService();
var contentRoot = env.ContentRootPath;
@@ -37,7 +37,7 @@ namespace Microsoft.Blazor.DevHost.Server
throw new FileNotFoundException($"Could not locate application assembly at expected location {assemblyPath}");
}
- return Assembly.LoadFile(assemblyPath);
+ return assemblyPath;
}
private static string FindClientBinDir(string clientAppSourceRoot)
diff --git a/src/Microsoft.Blazor.Server/BlazorAppBuilderExtensions.cs b/src/Microsoft.Blazor.Server/BlazorAppBuilderExtensions.cs
index 7f796faee5..eaacb4696c 100644
--- a/src/Microsoft.Blazor.Server/BlazorAppBuilderExtensions.cs
+++ b/src/Microsoft.Blazor.Server/BlazorAppBuilderExtensions.cs
@@ -1,11 +1,10 @@
// 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.AspNetCore.StaticFiles;
+using Microsoft.Blazor.Server;
using Microsoft.Blazor.Server.FrameworkFiles;
using Microsoft.Blazor.Server.WebRootFiles;
-using Microsoft.Extensions.DependencyInjection;
using System.Collections.Generic;
using System.IO;
using System.Net.Mime;
@@ -16,18 +15,28 @@ namespace Microsoft.AspNetCore.Builder
{
public static void UseBlazor(
this IApplicationBuilder applicationBuilder,
- string assemblyPath,
- string staticFilesRoot)
+ string clientAssemblyName)
{
- var frameworkFileProvider = FrameworkFileProvider.Instantiate(assemblyPath);
+ var binDir = Path.GetDirectoryName(typeof(BlazorConfig).Assembly.Location);
+ var clientAssemblyPath = Path.Combine(binDir, $"{clientAssemblyName}.dll");
+ applicationBuilder.UseBlazorInternal(clientAssemblyPath);
+ }
- if (staticFilesRoot != null)
+ // 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(
+ this IApplicationBuilder applicationBuilder,
+ string clientAssemblyPath)
+ {
+ var config = BlazorConfig.Read(clientAssemblyPath);
+ var frameworkFileProvider = FrameworkFileProvider.Instantiate(
+ config.SourceOutputAssemblyPath);
+
+ if (config.WebRootPath != null)
{
- var env = applicationBuilder.ApplicationServices.GetRequiredService();
- var clientWebRoot = Path.GetFullPath(Path.Combine(env.ContentRootPath, staticFilesRoot));
var webRootFileProvider = WebRootFileProvider.Instantiate(
- clientWebRoot,
- Path.GetFileNameWithoutExtension(assemblyPath),
+ config.WebRootPath,
+ Path.GetFileNameWithoutExtension(config.SourceOutputAssemblyPath),
frameworkFileProvider.GetDirectoryContents("/_bin"));
applicationBuilder.UseDefaultFiles(new DefaultFilesOptions
diff --git a/src/Microsoft.Blazor.Server/BlazorConfig.cs b/src/Microsoft.Blazor.Server/BlazorConfig.cs
new file mode 100644
index 0000000000..1592437a8c
--- /dev/null
+++ b/src/Microsoft.Blazor.Server/BlazorConfig.cs
@@ -0,0 +1,34 @@
+// 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 System.Linq;
+
+namespace Microsoft.Blazor.Server
+{
+ internal class BlazorConfig
+ {
+ public string SourceMSBuildPath { get; }
+ public string SourceOutputAssemblyPath { get; }
+ public string WebRootPath { get; }
+
+ public static BlazorConfig Read(string assemblyPath)
+ => new BlazorConfig(assemblyPath);
+
+ private BlazorConfig(string assemblyPath)
+ {
+ var configFilePath = Path.ChangeExtension(assemblyPath, ".blazor.config");
+ var configLines = File.ReadLines(configFilePath).ToList();
+ SourceMSBuildPath = configLines[0];
+
+ var sourceMsBuildDir = Path.GetDirectoryName(SourceMSBuildPath);
+ SourceOutputAssemblyPath = Path.Combine(sourceMsBuildDir, configLines[1]);
+
+ var webRootPath = Path.Combine(sourceMsBuildDir, "wwwroot");
+ if (Directory.Exists(webRootPath))
+ {
+ WebRootPath = webRootPath;
+ }
+ }
+ }
+}
diff --git a/src/Microsoft.Blazor.Server/Properties/AssemblyInfo.cs b/src/Microsoft.Blazor.Server/Properties/AssemblyInfo.cs
index 015cbd4cb3..c41b478df6 100644
--- a/src/Microsoft.Blazor.Server/Properties/AssemblyInfo.cs
+++ b/src/Microsoft.Blazor.Server/Properties/AssemblyInfo.cs
@@ -1,3 +1,4 @@
using System.Runtime.CompilerServices;
+[assembly: InternalsVisibleTo("Microsoft.Blazor.DevHost")]
[assembly: InternalsVisibleTo("Microsoft.Blazor.Server.Test")]