diff --git a/AspNetCore.sln b/AspNetCore.sln index 9e5ec5932ba1..e152dc8df6ba 100644 --- a/AspNetCore.sln +++ b/AspNetCore.sln @@ -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}" @@ -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 @@ -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} diff --git a/global.json b/global.json index 2769795efc49..aaed3448710c 100644 --- a/global.json +++ b/global.json @@ -1,9 +1,9 @@ { "sdk": { - "version": "6.0.100-preview.4.21216.8" + "version": "6.0.100-preview.4.21222.6" }, "tools": { - "dotnet": "6.0.100-preview.4.21216.8", + "dotnet": "6.0.100-preview.4.21222.6", "runtimes": { "dotnet/x64": [ "2.1.25", diff --git a/src/Http/HttpAbstractions.slnf b/src/Http/HttpAbstractions.slnf index 2b9c64391b89..4600bf38c850 100644 --- a/src/Http/HttpAbstractions.slnf +++ b/src/Http/HttpAbstractions.slnf @@ -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", diff --git a/src/Http/samples/MinimalSample/Program.cs b/src/Http/samples/MinimalSample/Program.cs index e83891ce94ed..ef09f60baf7c 100644 --- a/src/Http/samples/MinimalSample/Program.cs +++ b/src/Http/samples/MinimalSample/Program.cs @@ -1,10 +1,13 @@ 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)EchoTodo); +if (app.Environment.IsDevelopment()) +{ + app.UseDeveloperExceptionPage(); +} string Plaintext() => "Hello, World!"; app.MapGet("/plaintext", (Func)Plaintext); @@ -12,9 +15,7 @@ object Json() => new { message = "Hello, World!" }; app.MapGet("/json", (Func)Json); -string SayHello(string name) => $"Hello {name}"; +string SayHello(string name) => $"Hello, {name}!"; app.MapGet("/hello/{name}", (Func)SayHello); await app.RunAsync(); - -record Todo(int Id, string Name, bool IsComplete); diff --git a/src/Http/samples/MinimalSampleFSharp/MinimalSampleFSharp.fsproj b/src/Http/samples/MinimalSampleFSharp/MinimalSampleFSharp.fsproj new file mode 100644 index 000000000000..24e4bb3e6642 --- /dev/null +++ b/src/Http/samples/MinimalSampleFSharp/MinimalSampleFSharp.fsproj @@ -0,0 +1,20 @@ + + + + net6.0 + + + + + + + + + + + + + + + + diff --git a/src/Http/samples/MinimalSampleFSharp/Program.fs b/src/Http/samples/MinimalSampleFSharp/Program.fs new file mode 100644 index 000000000000..67600b9401f0 --- /dev/null +++ b/src/Http/samples/MinimalSampleFSharp/Program.fs @@ -0,0 +1,18 @@ +open System +open Microsoft.AspNetCore.Builder +open Microsoft.Extensions.Hosting + +[] +let main args = + use app = WebApplication.Create(args) + + if app.Environment.IsDevelopment() then + app.UseDeveloperExceptionPage() |> ignore + + app.MapGet("/plaintext", Func(fun () -> "Hello, World!")) |> ignore + app.MapGet("/json", Func<_>(fun () -> {| message = "Hello, World!" |})) |> ignore + app.MapGet("/hello/{name}", Func(fun name -> $"Hello, {name}!")) |> ignore + + app.Run() + + 0 // Exit code diff --git a/src/Http/samples/MinimalSampleFSharp/Properties/launchSettings.json b/src/Http/samples/MinimalSampleFSharp/Properties/launchSettings.json new file mode 100644 index 000000000000..c8d4f5da750f --- /dev/null +++ b/src/Http/samples/MinimalSampleFSharp/Properties/launchSettings.json @@ -0,0 +1,13 @@ +{ + "profiles": { + "MinimalSampleFSharp": { + "commandName": "Project", + "dotnetRunMessages": "true", + "launchBrowser": true, + "applicationUrl": "https://localhost:5001;http://localhost:5000", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/src/Http/samples/MinimalSampleFSharp/appsettings.Development.json b/src/Http/samples/MinimalSampleFSharp/appsettings.Development.json new file mode 100644 index 000000000000..8983e0fc1c5e --- /dev/null +++ b/src/Http/samples/MinimalSampleFSharp/appsettings.Development.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + } +} diff --git a/src/Http/samples/MinimalSampleFSharp/appsettings.json b/src/Http/samples/MinimalSampleFSharp/appsettings.json new file mode 100644 index 000000000000..d9d9a9bff6fd --- /dev/null +++ b/src/Http/samples/MinimalSampleFSharp/appsettings.json @@ -0,0 +1,10 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + }, + "AllowedHosts": "*" +} diff --git a/src/ProjectTemplates/Shared/Project.cs b/src/ProjectTemplates/Shared/Project.cs index 8176ea9abc77..84417ced0375 100644 --- a/src/ProjectTemplates/Shared/Project.cs +++ b/src/ProjectTemplates/Shared/Project.cs @@ -58,7 +58,7 @@ public class Project : IDisposable // Used to set special options in MSBuild IDictionary environmentVariables = null) { - var hiveArg = $"--debug:custom-hive \"{TemplatePackageInstaller.CustomHivePath}\""; + var hiveArg = $" --debug:disable-sdk-templates --debug:custom-hive \"{TemplatePackageInstaller.CustomHivePath}\""; var argString = $"new {templateName} {hiveArg}"; environmentVariables ??= new Dictionary(); if (!string.IsNullOrEmpty(auth)) @@ -323,7 +323,7 @@ internal async Task RunDotNetNewRawAsync(string arguments) AppContext.BaseDirectory, DotNetMuxer.MuxerPathOrDefault(), arguments + - $" --debug:custom-hive \"{TemplatePackageInstaller.CustomHivePath}\"" + + $" --debug:disable-sdk-templates --debug:custom-hive \"{TemplatePackageInstaller.CustomHivePath}\"" + $" -o {TemplateOutputDir}"); await result.Exited; return result; diff --git a/src/ProjectTemplates/Shared/TemplatePackageInstaller.cs b/src/ProjectTemplates/Shared/TemplatePackageInstaller.cs index a28b2c434677..9a6c698ffb33 100644 --- a/src/ProjectTemplates/Shared/TemplatePackageInstaller.cs +++ b/src/ProjectTemplates/Shared/TemplatePackageInstaller.cs @@ -43,11 +43,11 @@ internal static class TemplatePackageInstaller "Microsoft.AspNetCore.Blazor.Templates", }; - public static string CustomHivePath { get; } = (string.IsNullOrEmpty(Environment.GetEnvironmentVariable("helix"))) + public static string CustomHivePath { get; } = Path.GetFullPath((string.IsNullOrEmpty(Environment.GetEnvironmentVariable("helix"))) ? typeof(TemplatePackageInstaller) .Assembly.GetCustomAttributes() .Single(s => s.Key == "CustomTemplateHivePath").Value - : Path.Combine("Hives", ".templateEngine"); + : Path.Combine("Hives", ".templateEngine")); public static async Task EnsureTemplatingEngineInitializedAsync(ITestOutputHelper output) { @@ -78,7 +78,9 @@ public static async Task RunDotNetNew(ITestOutputHelper output, strin output, AppContext.BaseDirectory, DotNetMuxer.MuxerPathOrDefault(), - $"new {arguments} --debug:custom-hive \"{CustomHivePath}\""); + //--debug:disable-sdk-templates means, don't include C:\Program Files\dotnet\templates, aka. what comes with SDK, so we don't need to uninstall + //--debug:custom-hive means, don't install templates on CI/developer machine, instead create new temporary instance + $"new {arguments} --debug:disable-sdk-templates --debug:custom-hive \"{CustomHivePath}\""); await proc.Exited; @@ -105,23 +107,12 @@ private static async Task InstallTemplatePackages(ITestOutputHelper output) Assert.Equal(4, builtPackages.Length); - /* - * The templates are indexed by path, for example: - &USERPROFILE%\.templateengine\dotnetcli\v5.0.100-alpha1-013788\packages\nunit3.dotnetnew.template.1.6.1.nupkg - Templates: - NUnit 3 Test Project (nunit) C# - NUnit 3 Test Item (nunit-test) C# - NUnit 3 Test Project (nunit) F# - NUnit 3 Test Item (nunit-test) F# - NUnit 3 Test Project (nunit) VB - NUnit 3 Test Item (nunit-test) VB - Uninstall Command: - dotnet new -u &USERPROFILE%\.templateengine\dotnetcli\v5.0.100-alpha1-013788\packages\nunit3.dotnetnew.template.1.6.1.nupkg - - * We don't want to construct this path so we'll rely on dotnet new --uninstall --help to construct the uninstall command. - */ - // Workaround for https://github.com/dotnet/sdk/issues/16906 - // await UninstallExistingTemplatesAsync(output); + await VerifyCannotFindTemplateAsync(output, "web"); + await VerifyCannotFindTemplateAsync(output, "webapp"); + await VerifyCannotFindTemplateAsync(output, "mvc"); + await VerifyCannotFindTemplateAsync(output, "react"); + await VerifyCannotFindTemplateAsync(output, "reactredux"); + await VerifyCannotFindTemplateAsync(output, "angular"); foreach (var packagePath in builtPackages) { @@ -135,35 +126,6 @@ private static async Task InstallTemplatePackages(ITestOutputHelper output) await VerifyCanFindTemplate(output, "react"); } - private static async Task UninstallExistingTemplatesAsync(ITestOutputHelper output) - { - var proc = await RunDotNetNew(output, "--uninstall --help"); - var lines = proc.Output.Split(Environment.NewLine); - - // Remove any previous or prebundled version of the template packages - foreach (var packageName in _templatePackages) - { - // Depending on the ordering, there may be multiple matches: - // Microsoft.DotNet.Web.Spa.ProjectTemplates.3.0.3.0.0-preview7.*.nupkg - // Microsoft.DotNet.Web.Spa.ProjectTemplates.3.0.0-preview7.*.nupkg - // Error on the side of caution and uninstall all of them - foreach (var command in lines.Where(l => l.Contains("dotnet new") && l.Contains(packageName, StringComparison.OrdinalIgnoreCase))) - { - var uninstallCommand = command.TrimStart(); - Debug.Assert(uninstallCommand.StartsWith("dotnet new", StringComparison.Ordinal)); - uninstallCommand = uninstallCommand.Substring("dotnet new".Length); - await RunDotNetNew(output, uninstallCommand); - } - } - - await VerifyCannotFindTemplateAsync(output, "web"); - await VerifyCannotFindTemplateAsync(output, "webapp"); - await VerifyCannotFindTemplateAsync(output, "mvc"); - await VerifyCannotFindTemplateAsync(output, "react"); - await VerifyCannotFindTemplateAsync(output, "reactredux"); - await VerifyCannotFindTemplateAsync(output, "angular"); - } - private static async Task VerifyCanFindTemplate(ITestOutputHelper output, string templateName) { var proc = await RunDotNetNew(output, $""); diff --git a/src/ProjectTemplates/Web.ProjectTemplates/EmptyWeb-FSharp.fsproj.in b/src/ProjectTemplates/Web.ProjectTemplates/EmptyWeb-FSharp.fsproj.in index 0deda84e881f..e8bd76289806 100644 --- a/src/ProjectTemplates/Web.ProjectTemplates/EmptyWeb-FSharp.fsproj.in +++ b/src/ProjectTemplates/Web.ProjectTemplates/EmptyWeb-FSharp.fsproj.in @@ -1,4 +1,4 @@ - + ${DefaultNetCoreTargetFramework} @@ -7,7 +7,6 @@ - diff --git a/src/ProjectTemplates/Web.ProjectTemplates/content/EmptyWeb-CSharp/Program.cs b/src/ProjectTemplates/Web.ProjectTemplates/content/EmptyWeb-CSharp/Program.cs index 549d0b8bb8a1..55579e300076 100644 --- a/src/ProjectTemplates/Web.ProjectTemplates/content/EmptyWeb-CSharp/Program.cs +++ b/src/ProjectTemplates/Web.ProjectTemplates/content/EmptyWeb-CSharp/Program.cs @@ -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(); - }); - } +if (app.Environment.IsDevelopment()) +{ + app.UseDeveloperExceptionPage(); } + +app.MapGet("/", (Func)(() => "Hello World!")); + +await app.RunAsync(); diff --git a/src/ProjectTemplates/Web.ProjectTemplates/content/EmptyWeb-CSharp/Startup.cs b/src/ProjectTemplates/Web.ProjectTemplates/content/EmptyWeb-CSharp/Startup.cs deleted file mode 100644 index 078171e104f9..000000000000 --- a/src/ProjectTemplates/Web.ProjectTemplates/content/EmptyWeb-CSharp/Startup.cs +++ /dev/null @@ -1,40 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Http; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; - -namespace Company.WebApplication1 -{ - public class Startup - { - // This method gets called by the runtime. Use this method to add services to the container. - // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 - public void ConfigureServices(IServiceCollection services) - { - } - - // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. - public void Configure(IApplicationBuilder app, IWebHostEnvironment env) - { - if (env.IsDevelopment()) - { - app.UseDeveloperExceptionPage(); - } - - app.UseRouting(); - - app.UseEndpoints(endpoints => - { - endpoints.MapGet("/", async context => - { - await context.Response.WriteAsync("Hello World!"); - }); - }); - } - } -} diff --git a/src/ProjectTemplates/Web.ProjectTemplates/content/EmptyWeb-FSharp/Program.fs b/src/ProjectTemplates/Web.ProjectTemplates/content/EmptyWeb-FSharp/Program.fs index 78dd7f23b3bb..b2916aeb21e6 100644 --- a/src/ProjectTemplates/Web.ProjectTemplates/content/EmptyWeb-FSharp/Program.fs +++ b/src/ProjectTemplates/Web.ProjectTemplates/content/EmptyWeb-FSharp/Program.fs @@ -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() |> ignore - ) +[] +let main args = + let builder = WebApplication.CreateBuilder(args) + use app = builder.Build() + + if app.Environment.IsDevelopment() then + app.UseDeveloperExceptionPage() |> ignore + + app.MapGet("/", Func(fun () -> "Hello World!")) |> ignore + + app.Run() - [] - let main args = - createHostBuilder(args).Build().Run() + 0 // Exit code - 0 // Exit code diff --git a/src/ProjectTemplates/Web.ProjectTemplates/content/EmptyWeb-FSharp/Startup.fs b/src/ProjectTemplates/Web.ProjectTemplates/content/EmptyWeb-FSharp/Startup.fs deleted file mode 100644 index e728d9a8a579..000000000000 --- a/src/ProjectTemplates/Web.ProjectTemplates/content/EmptyWeb-FSharp/Startup.fs +++ /dev/null @@ -1,26 +0,0 @@ -namespace Company.WebApplication1 - -open System -open Microsoft.AspNetCore.Builder -open Microsoft.AspNetCore.Hosting -open Microsoft.AspNetCore.Http -open Microsoft.Extensions.DependencyInjection -open Microsoft.Extensions.Hosting - -type Startup() = - - // This method gets called by the runtime. Use this method to add services to the container. - // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 - member _.ConfigureServices(services: IServiceCollection) = - () - - // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. - member _.Configure(app: IApplicationBuilder, env: IWebHostEnvironment) = - if env.IsDevelopment() then - app.UseDeveloperExceptionPage() |> ignore - - app.UseRouting() - .UseEndpoints(fun endpoints -> - endpoints.MapGet("/", fun context -> - context.Response.WriteAsync("Hello World!")) |> ignore - ) |> ignore diff --git a/src/ProjectTemplates/test/template-baselines.json b/src/ProjectTemplates/test/template-baselines.json index 81224504a145..cae276951c67 100644 --- a/src/ProjectTemplates/test/template-baselines.json +++ b/src/ProjectTemplates/test/template-baselines.json @@ -371,7 +371,6 @@ "appsettings.Development.json", "appsettings.json", "Program.cs", - "Startup.cs", "Properties/launchSettings.json" ], "AuthOption": "None" @@ -383,7 +382,6 @@ "appsettings.Development.json", "appsettings.json", "Program.fs", - "Startup.fs", "Properties/launchSettings.json" ], "AuthOption": "None"