Components/Blazor template updates (#7709)

* In Blazor hosted template, only UseBlazorDebugging in development environment. Fixes #7275

* Enable HTTPS in the Razor Components template. Fixes #6928

* Reduce Razor Components template to one project. Fixes #6883

* Minor phrasing tweak

* In Razor Components template, change .cshtml to .razor, except _ViewImports.cshtml

* Put back LangVersion

* Update RazorComponentsTemplateTest
This commit is contained in:
Steve Sanderson 2019-02-20 13:16:05 +00:00 committed by GitHub
parent 7a2dfd3200
commit 895e1c69e0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
37 changed files with 84 additions and 135 deletions

View File

@ -25,6 +25,7 @@ namespace BlazorHosted_CSharp.Server
if (env.IsDevelopment()) if (env.IsDevelopment())
{ {
app.UseDeveloperExceptionPage(); app.UseDeveloperExceptionPage();
app.UseBlazorDebugging();
} }
app.UseMvc(routes => app.UseMvc(routes =>
@ -33,7 +34,6 @@ namespace BlazorHosted_CSharp.Server
}); });
app.UseBlazor<Client.Startup>(); app.UseBlazor<Client.Startup>();
app.UseBlazorDebugging();
} }
} }
} }

View File

@ -39,8 +39,7 @@
<ItemGroup> <ItemGroup>
<GeneratedContent Include="EmptyWeb-CSharp.csproj.in" OutputPath="content/EmptyWeb-CSharp/Company.WebApplication1.csproj" /> <GeneratedContent Include="EmptyWeb-CSharp.csproj.in" OutputPath="content/EmptyWeb-CSharp/Company.WebApplication1.csproj" />
<GeneratedContent Include="EmptyWeb-FSharp.fsproj.in" OutputPath="content/EmptyWeb-FSharp/Company.WebApplication1.fsproj" /> <GeneratedContent Include="EmptyWeb-FSharp.fsproj.in" OutputPath="content/EmptyWeb-FSharp/Company.WebApplication1.fsproj" />
<GeneratedContent Include="RazorComponentsWeb-CSharp.App.csproj.in" OutputPath="content/RazorComponentsWeb-CSharp/RazorComponentsWeb-CSharp.App/RazorComponentsWeb-CSharp.App.csproj" /> <GeneratedContent Include="RazorComponentsWeb-CSharp.csproj.in" OutputPath="content/RazorComponentsWeb-CSharp/RazorComponentsWeb-CSharp.csproj" />
<GeneratedContent Include="RazorComponentsWeb-CSharp.Server.csproj.in" OutputPath="content/RazorComponentsWeb-CSharp/RazorComponentsWeb-CSharp.Server/RazorComponentsWeb-CSharp.Server.csproj" />
<GeneratedContent Include="RazorPagesWeb-CSharp.csproj.in" OutputPath="content/RazorPagesWeb-CSharp/Company.WebApplication1.csproj" /> <GeneratedContent Include="RazorPagesWeb-CSharp.csproj.in" OutputPath="content/RazorPagesWeb-CSharp/Company.WebApplication1.csproj" />
<GeneratedContent Include="RazorClassLibrary-CSharp.csproj.in" OutputPath="content/RazorClassLibrary-CSharp/Company.RazorClassLibrary1.csproj" /> <GeneratedContent Include="RazorClassLibrary-CSharp.csproj.in" OutputPath="content/RazorClassLibrary-CSharp/Company.RazorClassLibrary1.csproj" />
<GeneratedContent Include="StarterWeb-CSharp.csproj.in" OutputPath="content/StarterWeb-CSharp/Company.WebApplication1.csproj" /> <GeneratedContent Include="StarterWeb-CSharp.csproj.in" OutputPath="content/StarterWeb-CSharp/Company.WebApplication1.csproj" />

View File

@ -1,14 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>7.3</LangVersion>
<RootNamespace Condition="'$(name)' != '$(name{-VALUE-FORMS-}safe_namespace)'">RazorComponentsWeb_CSharp.App</RootNamespace>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.Browser" Version="${MicrosoftAspNetCoreComponentsBrowserPackageVersion}" />
<PackageReference Include="Microsoft.AspNetCore.Components.Build" Version="${MicrosoftAspNetCoreComponentsBuildPackageVersion}" PrivateAssets="all" />
</ItemGroup>
</Project>

View File

@ -2,14 +2,12 @@
<PropertyGroup> <PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework> <TargetFramework>netcoreapp3.0</TargetFramework>
<LangVersion>7.3</LangVersion>
<NoDefaultLaunchSettingsFile Condition="'$(ExcludeLaunchSettings)' == 'True'">True</NoDefaultLaunchSettingsFile> <NoDefaultLaunchSettingsFile Condition="'$(ExcludeLaunchSettings)' == 'True'">True</NoDefaultLaunchSettingsFile>
<RootNamespace Condition="'$(name)' != '$(name{-VALUE-FORMS-}safe_namespace)'">RazorComponentsWeb_CSharp.Server</RootNamespace> <RootNamespace Condition="'$(name)' != '$(name{-VALUE-FORMS-}safe_namespace)'">RazorComponentsWeb_CSharp</RootNamespace>
<_RazorComponentInclude>Components\**\*.cshtml</_RazorComponentInclude>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\RazorComponentsWeb-CSharp.App\RazorComponentsWeb-CSharp.App.csproj" />
</ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.Server" Version="${MicrosoftAspNetCoreComponentsServerPackageVersion}" /> <PackageReference Include="Microsoft.AspNetCore.Components.Server" Version="${MicrosoftAspNetCoreComponentsServerPackageVersion}" />
</ItemGroup> </ItemGroup>

View File

@ -18,11 +18,6 @@
}, },
"sourceName": "RazorComponentsWeb-CSharp", "sourceName": "RazorComponentsWeb-CSharp",
"preferNameDirectory": true, "preferNameDirectory": true,
"guids": [
"4C26868E-5E7C-458D-82E3-040509D0C71F",
"5990939C-7E7B-4CFA-86FF-44CA5756498A",
"650B3CE7-2E93-4CC4-9F46-466686815EAA"
],
"sources": [ "sources": [
{ {
"modifiers": [ "modifiers": [
@ -31,12 +26,6 @@
"exclude": [ "exclude": [
"Properties/launchSettings.json" "Properties/launchSettings.json"
] ]
},
{
"condition": "(HostIdentifier != \"dotnetcli\" && HostIdentifier != \"dotnetcli-preview\")",
"exclude": [
"*.sln"
]
} }
] ]
} }
@ -48,10 +37,6 @@
"defaultValue": "false", "defaultValue": "false",
"description": "Whether to exclude launchSettings.json from the generated template." "description": "Whether to exclude launchSettings.json from the generated template."
}, },
"HostIdentifier": {
"type": "bind",
"binding": "HostIdentifier"
},
"HttpPort": { "HttpPort": {
"type": "parameter", "type": "parameter",
"datatype": "integer", "datatype": "integer",
@ -119,6 +104,10 @@
"description": "If specified, skips the automatic restore of the project on create.", "description": "If specified, skips the automatic restore of the project on create.",
"defaultValue": "false" "defaultValue": "false"
}, },
"RequiresHttps": {
"type": "computed",
"value": "(!NoHttps)"
},
"NoHttps": { "NoHttps": {
"type": "parameter", "type": "parameter",
"datatype": "bool", "datatype": "bool",
@ -128,16 +117,7 @@
}, },
"primaryOutputs": [ "primaryOutputs": [
{ {
"condition": "(HostIdentifier == \"dotnetcli\" || HostIdentifier == \"dotnetcli-preview\")", "path": "RazorComponentsWeb-CSharp.csproj"
"path": "RazorComponentsWeb-CSharp.sln"
},
{
"condition": "(HostIdentifier != \"dotnetcli\" && HostIdentifier != \"dotnetcli-preview\")",
"path": "RazorComponentsWeb-CSharp.Server/RazorComponentsWeb-CSharp.Server.csproj"
},
{
"condition": "(HostIdentifier != \"dotnetcli\" && HostIdentifier != \"dotnetcli-preview\")",
"path": "RazorComponentsWeb-CSharp.App/RazorComponentsWeb-CSharp.App.csproj"
} }
], ],
"defaultName": "WebApplication1", "defaultName": "WebApplication1",

View File

@ -1,10 +1,10 @@
@page "/fetchdata" @page "/fetchdata"
@using RazorComponentsWeb_CSharp.App.Services @using RazorComponentsWeb_CSharp.Services
@inject WeatherForecastService ForecastService @inject WeatherForecastService ForecastService
<h1>Weather forecast</h1> <h1>Weather forecast</h1>
<p>This component demonstrates fetching data from the server.</p> <p>This component demonstrates fetching data from a service.</p>
@if (forecasts == null) @if (forecasts == null)
{ {

View File

@ -1,4 +1,4 @@
<div class="top-row pl-4 navbar navbar-dark"> <div class="top-row pl-4 navbar navbar-dark">
<a class="navbar-brand" href="">RazorComponentsWeb-CSharp</a> <a class="navbar-brand" href="">RazorComponentsWeb-CSharp</a>
<button class="navbar-toggler" onclick="@ToggleNavMenu"> <button class="navbar-toggler" onclick="@ToggleNavMenu">
<span class="navbar-toggler-icon"></span> <span class="navbar-toggler-icon"></span>

View File

@ -0,0 +1,12 @@
using Microsoft.AspNetCore.Components.Builder;
namespace RazorComponentsWeb_CSharp.Components
{
public class Startup
{
public void Configure(IComponentsApplicationBuilder app)
{
app.AddComponent<App>("app");
}
}
}

View File

@ -2,5 +2,4 @@
@using Microsoft.AspNetCore.Components.Layouts @using Microsoft.AspNetCore.Components.Layouts
@using Microsoft.AspNetCore.Components.Routing @using Microsoft.AspNetCore.Components.Routing
@using Microsoft.JSInterop @using Microsoft.JSInterop
@using RazorComponentsWeb_CSharp.App @using RazorComponentsWeb_CSharp.Components.Shared
@using RazorComponentsWeb_CSharp.App.Shared

View File

@ -9,7 +9,7 @@ using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
namespace RazorComponentsWeb_CSharp.Server namespace RazorComponentsWeb_CSharp
{ {
public class Program public class Program
{ {

View File

@ -0,0 +1,35 @@
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:8080",
//#if(RequiresHttps)
"sslPort": 44300
//#else
"sslPort": 0
//#endif
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"RazorComponentsWeb-CSharp": {
"commandName": "Project",
"launchBrowser": true,
//#if(RequiresHttps)
"applicationUrl": "https://localhost:5001;http://localhost:5000",
//#else
"applicationUrl": "http://localhost:5000",
//#endif
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}

View File

@ -1,20 +0,0 @@
using Microsoft.AspNetCore.Components.Builder;
using Microsoft.Extensions.DependencyInjection;
using RazorComponentsWeb_CSharp.App.Services;
namespace RazorComponentsWeb_CSharp.App
{
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
// Example of a data service
services.AddSingleton<WeatherForecastService>();
}
public void Configure(IComponentsApplicationBuilder app)
{
app.AddComponent<App>("app");
}
}
}

View File

@ -1,50 +0,0 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27130.2027
MinimumVisualStudioVersion = 15.0.26124.0
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RazorComponentsWeb-CSharp.Server", "RazorComponentsWeb-CSharp.Server\RazorComponentsWeb-CSharp.Server.csproj", "{650B3CE7-2E93-4CC4-9F46-466686815EAA}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RazorComponentsWeb-CSharp.App", "RazorComponentsWeb-CSharp.App\RazorComponentsWeb-CSharp.App.csproj", "{5990939C-7E7B-4CFA-86FF-44CA5756498A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{5990939C-7E7B-4CFA-86FF-44CA5756498A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5990939C-7E7B-4CFA-86FF-44CA5756498A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5990939C-7E7B-4CFA-86FF-44CA5756498A}.Debug|x64.ActiveCfg = Debug|Any CPU
{5990939C-7E7B-4CFA-86FF-44CA5756498A}.Debug|x64.Build.0 = Debug|Any CPU
{5990939C-7E7B-4CFA-86FF-44CA5756498A}.Debug|x86.ActiveCfg = Debug|Any CPU
{5990939C-7E7B-4CFA-86FF-44CA5756498A}.Debug|x86.Build.0 = Debug|Any CPU
{5990939C-7E7B-4CFA-86FF-44CA5756498A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5990939C-7E7B-4CFA-86FF-44CA5756498A}.Release|Any CPU.Build.0 = Release|Any CPU
{5990939C-7E7B-4CFA-86FF-44CA5756498A}.Release|x64.ActiveCfg = Release|Any CPU
{5990939C-7E7B-4CFA-86FF-44CA5756498A}.Release|x64.Build.0 = Release|Any CPU
{5990939C-7E7B-4CFA-86FF-44CA5756498A}.Release|x86.ActiveCfg = Release|Any CPU
{5990939C-7E7B-4CFA-86FF-44CA5756498A}.Release|x86.Build.0 = Release|Any CPU
{650B3CE7-2E93-4CC4-9F46-466686815EAA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{650B3CE7-2E93-4CC4-9F46-466686815EAA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{650B3CE7-2E93-4CC4-9F46-466686815EAA}.Debug|x64.ActiveCfg = Debug|Any CPU
{650B3CE7-2E93-4CC4-9F46-466686815EAA}.Debug|x64.Build.0 = Debug|Any CPU
{650B3CE7-2E93-4CC4-9F46-466686815EAA}.Debug|x86.ActiveCfg = Debug|Any CPU
{650B3CE7-2E93-4CC4-9F46-466686815EAA}.Debug|x86.Build.0 = Debug|Any CPU
{650B3CE7-2E93-4CC4-9F46-466686815EAA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{650B3CE7-2E93-4CC4-9F46-466686815EAA}.Release|Any CPU.Build.0 = Release|Any CPU
{650B3CE7-2E93-4CC4-9F46-466686815EAA}.Release|x64.ActiveCfg = Release|Any CPU
{650B3CE7-2E93-4CC4-9F46-466686815EAA}.Release|x64.Build.0 = Release|Any CPU
{650B3CE7-2E93-4CC4-9F46-466686815EAA}.Release|x86.ActiveCfg = Release|Any CPU
{650B3CE7-2E93-4CC4-9F46-466686815EAA}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {4C26868E-5E7C-458D-82E3-040509D0C71F}
EndGlobalSection
EndGlobal

View File

@ -1,6 +1,6 @@
using System; using System;
namespace RazorComponentsWeb_CSharp.App.Services namespace RazorComponentsWeb_CSharp.Services
{ {
public class WeatherForecast public class WeatherForecast
{ {

View File

@ -2,7 +2,7 @@ using System;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace RazorComponentsWeb_CSharp.App.Services namespace RazorComponentsWeb_CSharp.Services
{ {
public class WeatherForecastService public class WeatherForecastService
{ {

View File

@ -5,10 +5,14 @@ using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
#if (RequiresHttps)
using Microsoft.AspNetCore.HttpsPolicy;
#endif
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Hosting;
using RazorComponentsWeb_CSharp.Services;
namespace RazorComponentsWeb_CSharp.Server namespace RazorComponentsWeb_CSharp
{ {
public class Startup public class Startup
{ {
@ -16,7 +20,8 @@ namespace RazorComponentsWeb_CSharp.Server
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services) public void ConfigureServices(IServiceCollection services)
{ {
services.AddRazorComponents<App.Startup>(); services.AddSingleton<WeatherForecastService>();
services.AddRazorComponents<Components.Startup>();
} }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
@ -26,9 +31,19 @@ namespace RazorComponentsWeb_CSharp.Server
{ {
app.UseDeveloperExceptionPage(); app.UseDeveloperExceptionPage();
} }
#if (RequiresHttps)
else
{
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
#endif
#if (RequiresHttps)
app.UseHttpsRedirection();
#endif
app.UseStaticFiles(); app.UseStaticFiles();
app.UseRazorComponents<App.Startup>(); app.UseRazorComponents<Components.Startup>();
} }
} }
} }

View File

@ -22,11 +22,6 @@ namespace Templates.Test
public void RazorComponentsTemplateWorks() public void RazorComponentsTemplateWorks()
{ {
RunDotNetNew("razorcomponents"); RunDotNetNew("razorcomponents");
// Run the "server" project
ProjectName += ".Server";
TemplateOutputDir = Path.Combine(TemplateOutputDir, ProjectName);
TestApplication(publish: false); TestApplication(publish: false);
TestApplication(publish: true); TestApplication(publish: true);
} }