Fix regression in app startup when running in E2E tests

This commit is contained in:
Steve Sanderson 2018-02-27 16:57:07 +00:00
parent ff5b6a7f30
commit de2bfe5162
6 changed files with 21 additions and 12 deletions

View File

@ -10,7 +10,7 @@
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\..\src\Microsoft.AspNetCore.Blazor.Server\Microsoft.AspNetCore.Blazor.Server.csproj" /> <ProjectReference Include="..\..\src\Microsoft.AspNetCore.Blazor.Server\Microsoft.AspNetCore.Blazor.Server.csproj" />
<ProjectReference Include="..\HostedInAspNet.Client\HostedInAspNet.Client.csproj" ReferenceOutputAssembly="false" /> <ProjectReference Include="..\HostedInAspNet.Client\HostedInAspNet.Client.csproj" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@ -23,7 +23,7 @@ namespace HostedInAspNet.Server
app.UseDeveloperExceptionPage(); app.UseDeveloperExceptionPage();
} }
app.UseBlazor("HostedInAspNet.Client"); app.UseBlazor<Client.Program>();
} }
} }
} }

View File

@ -10,7 +10,7 @@
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\..\src\Microsoft.AspNetCore.Blazor.Server\Microsoft.AspNetCore.Blazor.Server.csproj" /> <ProjectReference Include="..\..\src\Microsoft.AspNetCore.Blazor.Server\Microsoft.AspNetCore.Blazor.Server.csproj" />
<ProjectReference Include="..\MonoSanityClient\MonoSanityClient.csproj" ReferenceOutputAssembly="false" /> <ProjectReference Include="..\MonoSanityClient\MonoSanityClient.csproj" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@ -12,7 +12,7 @@ namespace MonoSanity
{ {
app.UseDeveloperExceptionPage(); app.UseDeveloperExceptionPage();
app.UseFileServer(new FileServerOptions { EnableDefaultFiles = true }); app.UseFileServer(new FileServerOptions { EnableDefaultFiles = true });
app.UseBlazor("MonoSanityClient"); app.UseBlazor<MonoSanityClient.Program>();
} }
} }
} }

View File

@ -0,0 +1,12 @@
// 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.
namespace MonoSanityClient
{
// Note: Not used at runtime. This exists only to give the server app some type to reference.
// In realistic scenarios you'd have a Program class for real.
public class Program
{
}
}

View File

@ -16,18 +16,15 @@ namespace Microsoft.AspNetCore.Builder
/// <summary> /// <summary>
/// Configures the middleware pipeline to work with Blazor. /// Configures the middleware pipeline to work with Blazor.
/// </summary> /// </summary>
/// <typeparam name="TProgram">Any type from the client app project. This is used to identify the client app assembly.</typeparam>
/// <param name="applicationBuilder"></param> /// <param name="applicationBuilder"></param>
/// <param name="clientAssemblyName" public static void UseBlazor<TProgram>(
/// >The name of the client assembly relative to the current bin directory.</param> this IApplicationBuilder applicationBuilder)
public static void UseBlazor(
this IApplicationBuilder applicationBuilder,
string clientAssemblyName)
{ {
var binDir = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location); var clientAssemblyInServerBinDir = typeof(TProgram).Assembly;
var clientAssemblyPath = Path.Combine(binDir, $"{clientAssemblyName}.dll");
applicationBuilder.UseBlazor(new BlazorOptions applicationBuilder.UseBlazor(new BlazorOptions
{ {
ClientAssemblyPath = clientAssemblyPath, ClientAssemblyPath = clientAssemblyInServerBinDir.Location,
}); });
} }