Skip to content

Commit 688ab7f

Browse files
committed
Fix dotnet-blazor serve
This wasn't properly forwarding the base path to the configuration. Basically nothing was setting RemainingArguments. We have a test project that sets the base path, but it was never used when debugging locally. I also cleaned this up a bit and changed it to use dotnet exec. This allow you to debug the CLI and related server pipeline, but has the tradeoff of not rebuilding.
1 parent 8cfa8ea commit 688ab7f

File tree

6 files changed

+50
-29
lines changed

6 files changed

+50
-29
lines changed

src/Components/blazor/benchmarks/Microsoft.AspNetCore.Blazor.E2EPerformance/Microsoft.AspNetCore.Blazor.E2EPerformance.csproj

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@
22

33
<PropertyGroup>
44
<TargetFramework>netstandard2.0</TargetFramework>
5-
6-
<!-- Local alternative to <RunArguments>blazor serve</RunArguments> -->
7-
<RunCommand>dotnet</RunCommand>
8-
<RunArguments>run --project ../../../blazor/src/Microsoft.AspNetCore.Blazor.Cli serve</RunArguments>
95
</PropertyGroup>
106

117
<ItemGroup>

src/Components/blazor/samples/StandaloneApp/StandaloneApp.csproj

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@
22

33
<PropertyGroup>
44
<TargetFramework>netstandard2.0</TargetFramework>
5-
6-
<!-- Local alternative to <RunArguments>blazor serve</RunArguments> -->
7-
<RunCommand>dotnet</RunCommand>
8-
<RunArguments>run --project ../../src/Microsoft.AspNetCore.Blazor.Cli serve</RunArguments>
95
</PropertyGroup>
106

117
<ItemGroup>

src/Components/blazor/src/Microsoft.AspNetCore.Blazor.Cli/Commands/ServeCommand.cs

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,30 @@
33

44
using Microsoft.AspNetCore.Hosting;
55
using Microsoft.Extensions.CommandLineUtils;
6-
using System;
7-
using System.Diagnostics;
8-
using System.Text.RegularExpressions;
96

107
namespace Microsoft.AspNetCore.Blazor.Cli.Commands
118
{
12-
class ServeCommand
9+
internal class ServeCommand : CommandLineApplication
1310
{
14-
public static void Command(CommandLineApplication command)
11+
public ServeCommand(CommandLineApplication parent)
12+
13+
// We pass arbitrary arguments through to the ASP.NET Core configuration
14+
: base(throwOnUnexpectedArg: false)
1515
{
16-
var remainingArgs = command.RemainingArguments.ToArray();
16+
Parent = parent;
17+
18+
Name = "serve";
19+
Description = "Serve requests to a Blazor application";
20+
21+
HelpOption("-?|-h|--help");
1722

18-
Server.Program.BuildWebHost(remainingArgs).Run();
23+
OnExecute(Execute);
24+
}
25+
26+
private int Execute()
27+
{
28+
Server.Program.BuildWebHost(RemainingArguments.ToArray()).Run();
29+
return 0;
1930
}
2031
}
2132
}

src/Components/blazor/src/Microsoft.AspNetCore.Blazor.Cli/Program.cs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,39 @@
1-
// Copyright (c) .NET Foundation. All rights reserved.
1+
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

4-
using Microsoft.AspNetCore.Hosting;
5-
using System;
6-
using System.Linq;
7-
using Microsoft.Extensions.CommandLineUtils;
84
using Microsoft.AspNetCore.Blazor.Cli.Commands;
5+
using Microsoft.Extensions.CommandLineUtils;
96

107
namespace Microsoft.AspNetCore.Blazor.Cli
118
{
129
internal class Program
1310
{
1411
static int Main(string[] args)
1512
{
16-
var app = new CommandLineApplication
13+
var app = new CommandLineApplication(throwOnUnexpectedArg: false)
1714
{
1815
Name = "blazor-cli"
1916
};
2017
app.HelpOption("-?|-h|--help");
2118

22-
app.Command("serve", ServeCommand.Command);
19+
app.Commands.Add(new ServeCommand(app));
2320

24-
if (args.Length > 0)
21+
// A command is always required
22+
app.OnExecute(() =>
23+
{
24+
app.ShowHelp();
25+
return 0;
26+
});
27+
28+
try
2529
{
2630
return app.Execute(args);
2731
}
28-
else
32+
catch (CommandParsingException cex)
2933
{
34+
app.Error.WriteLine(cex.Message);
3035
app.ShowHelp();
31-
return 0;
36+
return 1;
3237
}
3338
}
3439
}

src/Components/src/Microsoft.AspNetCore.Components.Build/ReferenceFromSource.props

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project>
1+
<Project>
22

33
<!--
44
Importing this file is equivalent to having:
@@ -17,6 +17,20 @@
1717
<Import Project="$(MSBuildThisFileDirectory)targets/All.props" />
1818
<Import Project="$(MSBuildThisFileDirectory)targets/All.targets" />
1919

20+
<!--
21+
Debugging support using dotnet-blazor serve.
22+
23+
A few things to note here:
24+
- We have to use dotnet exec to avoid launching another process and confusing the debugger.
25+
- Since we're doing dotnet exec, it won't automatically rebuild the CLI project.
26+
- $(AdditionalRunArguments) needs to be defined before importing this file.
27+
-->
28+
<PropertyGroup>
29+
<RunCommand>dotnet</RunCommand>
30+
<_BlazorCliLocation>$(MSBuildThisFileDirectory)../../blazor/src/Microsoft.AspNetCore.Blazor.Cli/bin/$(Configuration)/netcoreapp3.0/dotnet-blazor.dll </_BlazorCliLocation>
31+
<RunArguments>exec $(_BlazorCliLocation) serve $(AdditionalRunArguments)</RunArguments>
32+
</PropertyGroup>
33+
2034
<ItemGroup>
2135
<PackageReference Include="Microsoft.AspNetCore.Blazor.Mono" Version="$(MicrosoftAspNetCoreBlazorMonoPackageVersion)" />
2236
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="$(MicrosoftAspNetCoreRazorDesignPackageVersion)" />

src/Components/test/testapps/BasicTestApp/BasicTestApp.csproj

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
<PropertyGroup>
44
<TargetFramework>netstandard2.0</TargetFramework>
55

6-
<!-- Local alternative to <RunArguments>blazor serve</RunArguments> -->
7-
<RunCommand>dotnet</RunCommand>
8-
<RunArguments>run --project ../../../blazor/src/Microsoft.AspNetCore.Blazor.Cli serve --pathbase /subdir</RunArguments>
6+
<!-- Must be defined before ReferenceFromSource.props is imported -->
7+
<AdditionalRunArguments>--pathbase /subdir</AdditionalRunArguments>
98
</PropertyGroup>
109

1110
<!-- Local alternative to <PackageReference Include="Microsoft.AspNetCore.Components.Build" /> -->

0 commit comments

Comments
 (0)