-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Update "empty" web project templates to use minimal hostinng and routing #32003
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
Changes from all commits
f586466
ddaf769
fc8b60e
eb5546a
7ff1200
c4733b8
2fbc0e9
23caa4e
cc57bb8
850e934
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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); |
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> |
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" | ||
} | ||
} | ||
} |
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,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!")); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't like that we still have to explicitly cast to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Program+Startup before: 66 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 |
There was a problem hiding this comment.
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.There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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