Skip to content

Commit cd5106f

Browse files
In E2E tests, pass application assembly path to Blazor dev server
1 parent fd9ad7f commit cd5106f

File tree

5 files changed

+23
-27
lines changed

5 files changed

+23
-27
lines changed

src/Components/Blazor/Build/src/ReferenceFromSource.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
<PropertyGroup>
2929
<RunCommand>dotnet</RunCommand>
3030
<_BlazorCliLocation>$(MSBuildThisFileDirectory)../../DevServer/src/bin/$(Configuration)/netcoreapp3.0/blazor-devserver.dll</_BlazorCliLocation>
31-
<RunArguments>exec &quot;$(_BlazorCliLocation)&quot; serve &quot;$(MSBuildProjectDirectory)/$(OutputPath)$(TargetFileName)&quot; $(AdditionalRunArguments)</RunArguments>
31+
<RunArguments>exec &quot;$(_BlazorCliLocation)&quot; serve --applicationpath &quot;$(MSBuildProjectDirectory)/$(OutputPath)$(TargetFileName)&quot; $(AdditionalRunArguments)</RunArguments>
3232
</PropertyGroup>
3333

3434
<ItemGroup>

src/Components/Blazor/DevServer/src/Commands/ServeCommand.cs

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,28 +23,11 @@ public ServeCommand(CommandLineApplication parent)
2323

2424
HelpOption("-?|-h|--help");
2525

26-
ApplicationPath = new CommandArgument()
27-
{
28-
Description = "Path to the client application dll",
29-
MultipleValues = false,
30-
Name = "<PATH>",
31-
ShowInHelpText = true
32-
};
33-
Arguments.Add(ApplicationPath);
34-
3526
OnExecute(Execute);
3627
}
3728

38-
public CommandArgument ApplicationPath { get; private set; }
39-
4029
private int Execute()
4130
{
42-
if (string.IsNullOrWhiteSpace(ApplicationPath.Value))
43-
{
44-
throw new InvalidOperationException($"Invalid value for parameter '{nameof(ApplicationPath)}'. Value supplied: '{ApplicationPath.Value}'");
45-
}
46-
47-
Server.Startup.ApplicationAssembly = ApplicationPath.Value;
4831
Server.Program.BuildWebHost(RemainingArguments.ToArray()).Run();
4932
return 0;
5033
}

src/Components/Blazor/DevServer/src/Server/Startup.cs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@ namespace Microsoft.AspNetCore.Blazor.DevServer.Server
1717
{
1818
internal class Startup
1919
{
20-
public static string ApplicationAssembly { get; set; }
20+
public Startup(IConfiguration configuration)
21+
{
22+
Configuration = configuration;
23+
}
24+
25+
public IConfiguration Configuration { get; }
2126

2227
public void ConfigureServices(IServiceCollection services)
2328
{
@@ -35,7 +40,7 @@ public void ConfigureServices(IServiceCollection services)
3540

3641
public void Configure(IApplicationBuilder app, IWebHostEnvironment environment, IConfiguration configuration)
3742
{
38-
var applicationAssemblyFullPath = ResolveApplicationAssemblyFullPath(environment);
43+
var applicationAssemblyFullPath = ResolveApplicationAssemblyFullPath();
3944

4045
app.UseDeveloperExceptionPage();
4146
app.UseResponseCompression();
@@ -54,15 +59,22 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment environment,
5459
});
5560
}
5661

57-
private static string ResolveApplicationAssemblyFullPath(IWebHostEnvironment environment)
62+
private string ResolveApplicationAssemblyFullPath()
5863
{
59-
var applicationAssemblyFullPath = Path.Combine(environment.ContentRootPath, ApplicationAssembly);
60-
if (!File.Exists(applicationAssemblyFullPath))
64+
const string applicationPathKey = "applicationpath";
65+
var configuredApplicationPath = Configuration.GetValue<string>(applicationPathKey);
66+
if (string.IsNullOrEmpty(configuredApplicationPath))
67+
{
68+
throw new InvalidOperationException($"No value was supplied for the required option '{applicationPathKey}'.");
69+
}
70+
71+
var resolvedApplicationPath = Path.GetFullPath(configuredApplicationPath);
72+
if (!File.Exists(resolvedApplicationPath))
6173
{
62-
throw new InvalidOperationException($"Application assembly not found at {applicationAssemblyFullPath}.");
74+
throw new InvalidOperationException($"Application assembly not found at {resolvedApplicationPath}.");
6375
}
6476

65-
return applicationAssemblyFullPath;
77+
return resolvedApplicationPath;
6678
}
6779

6880
private static void EnableConfiguredPathbase(IApplicationBuilder app, IConfiguration configuration)

src/Components/Blazor/DevServer/src/build/Microsoft.AspNetCore.Blazor.DevServer.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
<PropertyGroup>
33
<_BlazorDevServerDll>$(MSBuildThisFileDirectory)../tools/blazor-devserver.dll</_BlazorDevServerDll>
44
<RunCommand>dotnet</RunCommand>
5-
<RunArguments>&quot;$(_BlazorDevServerDll)&quot; serve &quot;$(MSBuildProjectDirectory)/$(OutputPath)$(TargetFileName)&quot;</RunArguments>
5+
<RunArguments>&quot;$(_BlazorDevServerDll)&quot; serve --applicationpath &quot;$(MSBuildProjectDirectory)/$(OutputPath)$(TargetFileName)&quot;</RunArguments>
66
</PropertyGroup>
77
</Project>

src/Components/test/E2ETest/Infrastructure/ServerFixtures/DevHostServerFixture.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ protected override IWebHost CreateWebHost()
2222
{
2323
"--urls", "http://127.0.0.1:0",
2424
"--contentroot", ContentRoot,
25-
"--pathbase", PathBase
25+
"--pathbase", PathBase,
26+
"--applicationpath", typeof(TProgram).Assembly.Location,
2627
};
2728

2829
if (!string.IsNullOrEmpty(Environment))

0 commit comments

Comments
 (0)