diff --git a/src/Components/blazor/benchmarks/Microsoft.AspNetCore.Blazor.E2EPerformance/Microsoft.AspNetCore.Blazor.E2EPerformance.csproj b/src/Components/blazor/benchmarks/Microsoft.AspNetCore.Blazor.E2EPerformance/Microsoft.AspNetCore.Blazor.E2EPerformance.csproj
index 7e93b792fb..156441542c 100644
--- a/src/Components/blazor/benchmarks/Microsoft.AspNetCore.Blazor.E2EPerformance/Microsoft.AspNetCore.Blazor.E2EPerformance.csproj
+++ b/src/Components/blazor/benchmarks/Microsoft.AspNetCore.Blazor.E2EPerformance/Microsoft.AspNetCore.Blazor.E2EPerformance.csproj
@@ -2,10 +2,6 @@
netstandard2.0
-
-
- dotnet
- run --project ../../../blazor/src/Microsoft.AspNetCore.Blazor.Cli serve
diff --git a/src/Components/blazor/samples/StandaloneApp/StandaloneApp.csproj b/src/Components/blazor/samples/StandaloneApp/StandaloneApp.csproj
index 82b4494aad..156441542c 100644
--- a/src/Components/blazor/samples/StandaloneApp/StandaloneApp.csproj
+++ b/src/Components/blazor/samples/StandaloneApp/StandaloneApp.csproj
@@ -2,10 +2,6 @@
netstandard2.0
-
-
- dotnet
- run --project ../../src/Microsoft.AspNetCore.Blazor.Cli serve
diff --git a/src/Components/blazor/src/Microsoft.AspNetCore.Blazor.Cli/Commands/ServeCommand.cs b/src/Components/blazor/src/Microsoft.AspNetCore.Blazor.Cli/Commands/ServeCommand.cs
index ce16353a74..ae7a4d671a 100644
--- a/src/Components/blazor/src/Microsoft.AspNetCore.Blazor.Cli/Commands/ServeCommand.cs
+++ b/src/Components/blazor/src/Microsoft.AspNetCore.Blazor.Cli/Commands/ServeCommand.cs
@@ -3,19 +3,30 @@
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.CommandLineUtils;
-using System;
-using System.Diagnostics;
-using System.Text.RegularExpressions;
namespace Microsoft.AspNetCore.Blazor.Cli.Commands
{
- class ServeCommand
+ internal class ServeCommand : CommandLineApplication
{
- public static void Command(CommandLineApplication command)
- {
- var remainingArgs = command.RemainingArguments.ToArray();
+ public ServeCommand(CommandLineApplication parent)
- Server.Program.BuildWebHost(remainingArgs).Run();
+ // We pass arbitrary arguments through to the ASP.NET Core configuration
+ : base(throwOnUnexpectedArg: false)
+ {
+ Parent = parent;
+
+ Name = "serve";
+ Description = "Serve requests to a Blazor application";
+
+ HelpOption("-?|-h|--help");
+
+ OnExecute(Execute);
+ }
+
+ private int Execute()
+ {
+ Server.Program.BuildWebHost(RemainingArguments.ToArray()).Run();
+ return 0;
}
}
}
diff --git a/src/Components/blazor/src/Microsoft.AspNetCore.Blazor.Cli/Program.cs b/src/Components/blazor/src/Microsoft.AspNetCore.Blazor.Cli/Program.cs
index 288715da4b..dcc71099b1 100644
--- a/src/Components/blazor/src/Microsoft.AspNetCore.Blazor.Cli/Program.cs
+++ b/src/Components/blazor/src/Microsoft.AspNetCore.Blazor.Cli/Program.cs
@@ -1,11 +1,8 @@
-// Copyright (c) .NET Foundation. All rights reserved.
+// 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 System;
-using System.Linq;
-using Microsoft.Extensions.CommandLineUtils;
using Microsoft.AspNetCore.Blazor.Cli.Commands;
+using Microsoft.Extensions.CommandLineUtils;
namespace Microsoft.AspNetCore.Blazor.Cli
{
@@ -13,22 +10,30 @@ namespace Microsoft.AspNetCore.Blazor.Cli
{
static int Main(string[] args)
{
- var app = new CommandLineApplication
+ var app = new CommandLineApplication(throwOnUnexpectedArg: false)
{
Name = "blazor-cli"
};
app.HelpOption("-?|-h|--help");
- app.Command("serve", ServeCommand.Command);
+ app.Commands.Add(new ServeCommand(app));
- if (args.Length > 0)
- {
- return app.Execute(args);
- }
- else
+ // A command is always required
+ app.OnExecute(() =>
{
app.ShowHelp();
return 0;
+ });
+
+ try
+ {
+ return app.Execute(args);
+ }
+ catch (CommandParsingException cex)
+ {
+ app.Error.WriteLine(cex.Message);
+ app.ShowHelp();
+ return 1;
}
}
}
diff --git a/src/Components/src/Microsoft.AspNetCore.Components.Build/ReferenceFromSource.props b/src/Components/src/Microsoft.AspNetCore.Components.Build/ReferenceFromSource.props
index f524d0cc37..4fbfbac254 100644
--- a/src/Components/src/Microsoft.AspNetCore.Components.Build/ReferenceFromSource.props
+++ b/src/Components/src/Microsoft.AspNetCore.Components.Build/ReferenceFromSource.props
@@ -1,4 +1,4 @@
-
+
+
+ dotnet
+ <_BlazorCliLocation>$(MSBuildThisFileDirectory)../../blazor/src/Microsoft.AspNetCore.Blazor.Cli/bin/$(Configuration)/netcoreapp3.0/dotnet-blazor.dll
+ exec $(_BlazorCliLocation) serve $(AdditionalRunArguments)
+
+
diff --git a/src/Components/test/testapps/BasicTestApp/BasicTestApp.csproj b/src/Components/test/testapps/BasicTestApp/BasicTestApp.csproj
index 7651dd7cec..b1fa526fd7 100644
--- a/src/Components/test/testapps/BasicTestApp/BasicTestApp.csproj
+++ b/src/Components/test/testapps/BasicTestApp/BasicTestApp.csproj
@@ -3,9 +3,8 @@
netstandard2.0
-
- dotnet
- run --project ../../../blazor/src/Microsoft.AspNetCore.Blazor.Cli serve --pathbase /subdir
+
+ --pathbase /subdir