Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update "empty" web project templates to use minimal hostinng and routing #32003

Merged
merged 10 commits into from
Apr 23, 2021
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions AspNetCore.sln
Original file line number Diff line number Diff line change
Expand Up @@ -1626,6 +1626,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.AspNetCore.SpaSer
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MinimalSample", "src\Http\samples\MinimalSample\MinimalSample.csproj", "{9647D8B7-4616-4E05-B258-BAD5CAEEDD38}"
EndProject
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "MinimalSampleFSharp", "src\Http\samples\MinimalSampleFSharp\MinimalSampleFSharp.fsproj", "{11BE4471-6C3D-4758-881A-97B6A16F21F6}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "HttpLogging", "HttpLogging", "{022B4B80-E813-4256-8034-11A68146F4EF}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.HttpLogging", "src\Middleware\HttpLogging\src\Microsoft.AspNetCore.HttpLogging.csproj", "{FF413F1C-A998-4FA2-823F-52AC0916B35C}"
Expand Down Expand Up @@ -7717,6 +7719,18 @@ Global
{9647D8B7-4616-4E05-B258-BAD5CAEEDD38}.Release|x64.Build.0 = Release|Any CPU
{9647D8B7-4616-4E05-B258-BAD5CAEEDD38}.Release|x86.ActiveCfg = Release|Any CPU
{9647D8B7-4616-4E05-B258-BAD5CAEEDD38}.Release|x86.Build.0 = Release|Any CPU
{11BE4471-6C3D-4758-881A-97B6A16F21F6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{11BE4471-6C3D-4758-881A-97B6A16F21F6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{11BE4471-6C3D-4758-881A-97B6A16F21F6}.Debug|x64.ActiveCfg = Debug|Any CPU
{11BE4471-6C3D-4758-881A-97B6A16F21F6}.Debug|x64.Build.0 = Debug|Any CPU
{11BE4471-6C3D-4758-881A-97B6A16F21F6}.Debug|x86.ActiveCfg = Debug|Any CPU
{11BE4471-6C3D-4758-881A-97B6A16F21F6}.Debug|x86.Build.0 = Debug|Any CPU
{11BE4471-6C3D-4758-881A-97B6A16F21F6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{11BE4471-6C3D-4758-881A-97B6A16F21F6}.Release|Any CPU.Build.0 = Release|Any CPU
{11BE4471-6C3D-4758-881A-97B6A16F21F6}.Release|x64.ActiveCfg = Release|Any CPU
{11BE4471-6C3D-4758-881A-97B6A16F21F6}.Release|x64.Build.0 = Release|Any CPU
{11BE4471-6C3D-4758-881A-97B6A16F21F6}.Release|x86.ActiveCfg = Release|Any CPU
{11BE4471-6C3D-4758-881A-97B6A16F21F6}.Release|x86.Build.0 = Release|Any CPU
{FF413F1C-A998-4FA2-823F-52AC0916B35C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FF413F1C-A998-4FA2-823F-52AC0916B35C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FF413F1C-A998-4FA2-823F-52AC0916B35C}.Debug|x64.ActiveCfg = Debug|Any CPU
Expand Down Expand Up @@ -8558,6 +8572,7 @@ Global
{DF4637DA-5F07-4903-8461-4E2DAB235F3C} = {7F99E967-3DC1-4198-9D55-47CD9471D0B6}
{AAB50C64-39AA-4AED-8E9C-50D68E7751AD} = {7F99E967-3DC1-4198-9D55-47CD9471D0B6}
{9647D8B7-4616-4E05-B258-BAD5CAEEDD38} = {EB5E294B-9ED5-43BF-AFA9-1CD2327F3DC1}
{11BE4471-6C3D-4758-881A-97B6A16F21F6} = {EB5E294B-9ED5-43BF-AFA9-1CD2327F3DC1}
{022B4B80-E813-4256-8034-11A68146F4EF} = {E5963C9F-20A6-4385-B364-814D2581FADF}
{FF413F1C-A998-4FA2-823F-52AC0916B35C} = {022B4B80-E813-4256-8034-11A68146F4EF}
{3A1EC883-EF9C-43E8-95E5-6B527428867B} = {022B4B80-E813-4256-8034-11A68146F4EF}
Expand Down
4 changes: 2 additions & 2 deletions global.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"sdk": {
"version": "6.0.100-preview.4.21216.8"
"version": "6.0.100-preview.4.21222.6"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heads up @dotnet/aspnet-build. I'm updating the preview4 branch SDK version so we can consume the WebApplication related types from our new "empty" web project templtates.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If these new types come from dotnet/aspnetcore, something is very wrong if they aren't just showing up. Fine if, on the other hand, the main thing we need is @DavidKarlas' dotnet/templating#3078 fix.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I needed to update this to get EmptyWebTemplateTest.EmptyWebTemplateCSharp EmptyWebTemplateTest.EmptyWebTemplateFSharp passing locally and on helix, so there's definitely room for improvement here. Not sure how common it is to update the templates to use very-newly-added APIs.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My understanding of the fix to templating is that the regression broke the custom hive logic we were using to make our template tests find our updated templates, so that's why stefan had to update the sdk. The templating workaround PR should also fix the tests I would assume

},
"tools": {
"dotnet": "6.0.100-preview.4.21216.8",
"dotnet": "6.0.100-preview.4.21222.6",
"runtimes": {
"dotnet/x64": [
"2.1.25",
Expand Down
1 change: 1 addition & 0 deletions src/Http/HttpAbstractions.slnf
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"src\\Http\\WebUtilities\\perf\\Microbenchmarks\\Microsoft.AspNetCore.WebUtilities.Microbenchmarks.csproj",
"src\\Http\\WebUtilities\\src\\Microsoft.AspNetCore.WebUtilities.csproj",
"src\\Http\\WebUtilities\\test\\Microsoft.AspNetCore.WebUtilities.Tests.csproj",
"src\\Http\\samples\\MinimalSampleFSharp\\MinimalSampleFSharp.fsproj",
"src\\Http\\samples\\MinimalSample\\MinimalSample.csproj",
"src\\Http\\samples\\SampleApp\\HttpAbstractions.SampleApp.csproj",
"src\\Middleware\\CORS\\src\\Microsoft.AspNetCore.Cors.csproj",
Expand Down
13 changes: 7 additions & 6 deletions src/Http/samples/MinimalSample/Program.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
using System;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.Hosting;

await using var app = WebApplication.Create();
await using var app = WebApplication.Create(args);
halter73 marked this conversation as resolved.
Show resolved Hide resolved

Todo EchoTodo(Todo todo) => todo;
app.MapPost("/EchoTodo", (Func<Todo, Todo>)EchoTodo);
if (app.Environment.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}

string Plaintext() => "Hello, World!";
app.MapGet("/plaintext", (Func<string>)Plaintext);

object Json() => new { message = "Hello, World!" };
app.MapGet("/json", (Func<object>)Json);

string SayHello(string name) => $"Hello {name}";
string SayHello(string name) => $"Hello, {name}!";
app.MapGet("/hello/{name}", (Func<string, string>)SayHello);

await app.RunAsync();

record Todo(int Id, string Name, bool IsComplete);
20 changes: 20 additions & 0 deletions src/Http/samples/MinimalSampleFSharp/MinimalSampleFSharp.fsproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<Compile Include="Program.fs" />
</ItemGroup>

<ItemGroup>
<Reference Include="Microsoft.AspNetCore" />
<Reference Include="Microsoft.AspNetCore.Diagnostics" />
<Reference Include="Microsoft.AspNetCore.Hosting" />
<!-- Mvc.Core is referenced only for its attributes -->
<Reference Include="Microsoft.AspNetCore.Mvc.Core" />
<Reference Include="Microsoft.AspNetCore.Server.Kestrel" />
</ItemGroup>

</Project>
18 changes: 18 additions & 0 deletions src/Http/samples/MinimalSampleFSharp/Program.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
open System
open Microsoft.AspNetCore.Builder
open Microsoft.Extensions.Hosting

[<EntryPoint>]
let main args =
use app = WebApplication.Create(args)

if app.Environment.IsDevelopment() then
app.UseDeveloperExceptionPage() |> ignore

app.MapGet("/plaintext", Func<string>(fun () -> "Hello, World!")) |> ignore
app.MapGet("/json", Func<_>(fun () -> {| message = "Hello, World!" |})) |> ignore
app.MapGet("/hello/{name}", Func<string, string>(fun name -> $"Hello, {name}!")) |> ignore

app.Run()

0 // Exit code
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"profiles": {
"MinimalSampleFSharp": {
"commandName": "Project",
"dotnetRunMessages": "true",
"launchBrowser": true,
"applicationUrl": "https://localhost:5001;http://localhost:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
}
}
10 changes: 10 additions & 0 deletions src/Http/samples/MinimalSampleFSharp/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>${DefaultNetCoreTargetFramework}</TargetFramework>
Expand All @@ -7,7 +7,6 @@
</PropertyGroup>

<ItemGroup>
<Compile Include="Startup.fs" />
<Compile Include="Program.fs" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
halter73 marked this conversation as resolved.
Show resolved Hide resolved

namespace Company.WebApplication1
{
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}
var builder = WebApplication.CreateBuilder(args);
await using var app = builder.Build();

public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
});
}
if (app.Environment.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}

app.MapGet("/", (Func<string>)(() => "Hello World!"));
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like that we still have to explicitly cast to Func<string> until we can consume the changes in dotnet/roslyn#52448, but I still think this is already a big improvement overall.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The bits should be lining up for preview 4 to allow this cast to be removed.


await app.RunAsync();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Program+Startup before: 66 lines
after: 14 lines.

It's a lot emptier than it used to be 😁.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,25 +1,18 @@
namespace Company.WebApplication1

open System
open System.Collections.Generic
open System.IO
open System.Linq
open System.Threading.Tasks
open Microsoft.AspNetCore
open Microsoft.AspNetCore.Hosting
open Microsoft.Extensions.Configuration
open Microsoft.AspNetCore.Builder
open Microsoft.Extensions.Hosting
open Microsoft.Extensions.Logging

module Program =
let createHostBuilder args =
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(fun webBuilder ->
webBuilder.UseStartup<Startup>() |> ignore
)
[<EntryPoint>]
let main args =
let builder = WebApplication.CreateBuilder(args)
use app = builder.Build()

if app.Environment.IsDevelopment() then
app.UseDeveloperExceptionPage() |> ignore

app.MapGet("/", Func<string>(fun () -> "Hello World!")) |> ignore

app.Run()

[<EntryPoint>]
let main args =
createHostBuilder(args).Build().Run()
0 // Exit code

0 // Exit code

This file was deleted.

2 changes: 0 additions & 2 deletions src/ProjectTemplates/test/template-baselines.json
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,6 @@
"appsettings.Development.json",
"appsettings.json",
"Program.cs",
"Startup.cs",
"Properties/launchSettings.json"
],
"AuthOption": "None"
Expand All @@ -383,7 +382,6 @@
"appsettings.Development.json",
"appsettings.json",
"Program.fs",
"Startup.fs",
"Properties/launchSettings.json"
],
"AuthOption": "None"
Expand Down