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.
This commit is contained in:
Ryan Nowak 2018-12-29 17:15:54 -08:00
parent 8cfa8ea64a
commit 688ab7fc49
6 changed files with 53 additions and 32 deletions

View File

@ -2,10 +2,6 @@
<PropertyGroup> <PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework> <TargetFramework>netstandard2.0</TargetFramework>
<!-- Local alternative to <RunArguments>blazor serve</RunArguments> -->
<RunCommand>dotnet</RunCommand>
<RunArguments>run --project ../../../blazor/src/Microsoft.AspNetCore.Blazor.Cli serve</RunArguments>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>

View File

@ -2,10 +2,6 @@
<PropertyGroup> <PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework> <TargetFramework>netstandard2.0</TargetFramework>
<!-- Local alternative to <RunArguments>blazor serve</RunArguments> -->
<RunCommand>dotnet</RunCommand>
<RunArguments>run --project ../../src/Microsoft.AspNetCore.Blazor.Cli serve</RunArguments>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>

View File

@ -3,19 +3,30 @@
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.CommandLineUtils; using Microsoft.Extensions.CommandLineUtils;
using System;
using System.Diagnostics;
using System.Text.RegularExpressions;
namespace Microsoft.AspNetCore.Blazor.Cli.Commands namespace Microsoft.AspNetCore.Blazor.Cli.Commands
{ {
class ServeCommand internal class ServeCommand : CommandLineApplication
{ {
public static void Command(CommandLineApplication command) public ServeCommand(CommandLineApplication parent)
{
var remainingArgs = command.RemainingArguments.ToArray();
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;
} }
} }
} }

View File

@ -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. // 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.AspNetCore.Blazor.Cli.Commands;
using Microsoft.Extensions.CommandLineUtils;
namespace Microsoft.AspNetCore.Blazor.Cli namespace Microsoft.AspNetCore.Blazor.Cli
{ {
@ -13,22 +10,30 @@ namespace Microsoft.AspNetCore.Blazor.Cli
{ {
static int Main(string[] args) static int Main(string[] args)
{ {
var app = new CommandLineApplication var app = new CommandLineApplication(throwOnUnexpectedArg: false)
{ {
Name = "blazor-cli" Name = "blazor-cli"
}; };
app.HelpOption("-?|-h|--help"); app.HelpOption("-?|-h|--help");
app.Command("serve", ServeCommand.Command); app.Commands.Add(new ServeCommand(app));
if (args.Length > 0) // A command is always required
{ app.OnExecute(() =>
return app.Execute(args);
}
else
{ {
app.ShowHelp(); app.ShowHelp();
return 0; return 0;
});
try
{
return app.Execute(args);
}
catch (CommandParsingException cex)
{
app.Error.WriteLine(cex.Message);
app.ShowHelp();
return 1;
} }
} }
} }

View File

@ -1,4 +1,4 @@
<Project> <Project>
<!-- <!--
Importing this file is equivalent to having: Importing this file is equivalent to having:
@ -17,6 +17,20 @@
<Import Project="$(MSBuildThisFileDirectory)targets/All.props" /> <Import Project="$(MSBuildThisFileDirectory)targets/All.props" />
<Import Project="$(MSBuildThisFileDirectory)targets/All.targets" /> <Import Project="$(MSBuildThisFileDirectory)targets/All.targets" />
<!--
Debugging support using dotnet-blazor serve.
A few things to note here:
- We have to use dotnet exec to avoid launching another process and confusing the debugger.
- Since we're doing dotnet exec, it won't automatically rebuild the CLI project.
- $(AdditionalRunArguments) needs to be defined before importing this file.
-->
<PropertyGroup>
<RunCommand>dotnet</RunCommand>
<_BlazorCliLocation>$(MSBuildThisFileDirectory)../../blazor/src/Microsoft.AspNetCore.Blazor.Cli/bin/$(Configuration)/netcoreapp3.0/dotnet-blazor.dll </_BlazorCliLocation>
<RunArguments>exec $(_BlazorCliLocation) serve $(AdditionalRunArguments)</RunArguments>
</PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Blazor.Mono" Version="$(MicrosoftAspNetCoreBlazorMonoPackageVersion)" /> <PackageReference Include="Microsoft.AspNetCore.Blazor.Mono" Version="$(MicrosoftAspNetCoreBlazorMonoPackageVersion)" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="$(MicrosoftAspNetCoreRazorDesignPackageVersion)" /> <PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="$(MicrosoftAspNetCoreRazorDesignPackageVersion)" />

View File

@ -3,9 +3,8 @@
<PropertyGroup> <PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework> <TargetFramework>netstandard2.0</TargetFramework>
<!-- Local alternative to <RunArguments>blazor serve</RunArguments> --> <!-- Must be defined before ReferenceFromSource.props is imported -->
<RunCommand>dotnet</RunCommand> <AdditionalRunArguments>--pathbase /subdir</AdditionalRunArguments>
<RunArguments>run --project ../../../blazor/src/Microsoft.AspNetCore.Blazor.Cli serve --pathbase /subdir</RunArguments>
</PropertyGroup> </PropertyGroup>
<!-- Local alternative to <PackageReference Include="Microsoft.AspNetCore.Components.Build" /> --> <!-- Local alternative to <PackageReference Include="Microsoft.AspNetCore.Components.Build" /> -->