-
Notifications
You must be signed in to change notification settings - Fork 9.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update "empty" web project templates to use minimal hostinng and rout…
…ing (#32003) * Minimize EmptyWeb-CSharp project template * Add UseDeveloperExceptionPage() back * Minimize EmptyWeb-FSharp project template * Add MinimalSampleFSharp * upcast * Fix tests * Show WebApplicationBuilder * _ * Update SDK to 6.0.100-preview.4.21222.6 * Fixes #32028: Investigate Template Baseline tests errors Latest `dotnet new` doesn't work with relative path for `--debug:custom-hive`... Hence make it absolute Also switched to using `--debug:disable-sdk-templates` to avoid potential conflict between SDK and tests installed templates. Co-authored-by: David Karlaš <david.karlas@microsoft.com>
- Loading branch information
1 parent
c515372
commit 90137b0
Showing
17 changed files
with
132 additions
and
170 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
|
||
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
20
src/Http/samples/MinimalSampleFSharp/MinimalSampleFSharp.fsproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
13 changes: 13 additions & 0 deletions
13
src/Http/samples/MinimalSampleFSharp/Properties/launchSettings.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/Http/samples/MinimalSampleFSharp/appsettings.Development.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"Logging": { | ||
"LogLevel": { | ||
"Default": "Information", | ||
"Microsoft": "Warning", | ||
"Microsoft.Hosting.Lifetime": "Information" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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": "*" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 10 additions & 21 deletions
31
src/ProjectTemplates/Web.ProjectTemplates/content/EmptyWeb-CSharp/Program.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
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!")); | ||
|
||
await app.RunAsync(); |
40 changes: 0 additions & 40 deletions
40
src/ProjectTemplates/Web.ProjectTemplates/content/EmptyWeb-CSharp/Startup.cs
This file was deleted.
Oops, something went wrong.
33 changes: 13 additions & 20 deletions
33
src/ProjectTemplates/Web.ProjectTemplates/content/EmptyWeb-FSharp/Program.fs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.