Skip to content

Instantly share code, notes, and snippets.

@IEvangelist
Last active February 1, 2023 19:14
Show Gist options
  • Select an option

  • Save IEvangelist/5c5706221fed67fe1fb87f98b49b4ff6 to your computer and use it in GitHub Desktop.

Select an option

Save IEvangelist/5c5706221fed67fe1fb87f98b49b4ff6 to your computer and use it in GitHub Desktop.

Revisions

  1. IEvangelist revised this gist Feb 1, 2023. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions smallest.md
    Original file line number Diff line number Diff line change
    @@ -8,6 +8,9 @@ app.MapGet("/", () => "Hello World!");
    app.Run();
    ```

    <details>
    <summary>Expand to see *Sample.cspoj* and *launchSettings.json* files</summary>

    **Sample.csproj**:

    ```xml
    @@ -53,6 +56,7 @@ app.Run();
    ![image](https://user-images.githubusercontent.com/7679720/216140158-3af1d774-84b3-45fe-b0e4-8732b58c7e3b.png)

    </details>

    Run the app:

  2. IEvangelist revised this gist Feb 1, 2023. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions smallest.md
    Original file line number Diff line number Diff line change
    @@ -48,6 +48,12 @@ app.Run();
    }
    ```

    > **Note**
    > The *appsettings.json* file is optional
    ![image](https://user-images.githubusercontent.com/7679720/216140158-3af1d774-84b3-45fe-b0e4-8732b58c7e3b.png)


    Run the app:

    ![image](https://user-images.githubusercontent.com/7679720/216138994-f260d870-04eb-4b5d-ba89-5259519fce65.png)
  3. IEvangelist revised this gist Feb 1, 2023. 1 changed file with 49 additions and 6 deletions.
    55 changes: 49 additions & 6 deletions smallest.md
    Original file line number Diff line number Diff line change
    @@ -1,10 +1,53 @@
    This is a sample app, trying to demonstrate the smallest ASP.NET Core Minimal API, a "Hello World!" example. The *Program.cs** is only three lines of code.

    **Program.cs**:

    ```csharp
    using Microsoft.AspNetCore;
    using Microsoft.AspNetCore.Hosting;
    using Microsoft.AspNetCore.Http;
    var app = WebApplication.CreateBuilder(args).Build();
    app.MapGet("/", () => "Hello World!");
    app.Run();
    ```

    **Sample.csproj**:

    ```xml
    <Project Sdk="Microsoft.NET.Sdk.Web">
    <PropertyGroup>
    <TargetFramework>net7.0</TargetFramework>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
    </PropertyGroup>
    </Project>
    ```

    public class Program
    **Properties/launchSettings.json**:

    ```json
    {
    static void Main() => WebHost.Start(ctx => ctx.Response.WriteAsync("Hello World!")).WaitForShutdown();
    "$schema": "https://json.schemastore.org/launchsettings.json",
    "profiles": {
    "http": {
    "commandName": "Project",
    "dotnetRunMessages": true,
    "launchBrowser": true,
    "applicationUrl": "http://localhost:5029",
    "environmentVariables": {
    "ASPNETCORE_ENVIRONMENT": "Development"
    }
    },
    "https": {
    "commandName": "Project",
    "dotnetRunMessages": true,
    "launchBrowser": true,
    "applicationUrl": "https://localhost:7263;http://localhost:5029",
    "environmentVariables": {
    "ASPNETCORE_ENVIRONMENT": "Development"
    }
    }
    }
    }
    ```
    ```

    Run the app:

    ![image](https://user-images.githubusercontent.com/7679720/216138994-f260d870-04eb-4b5d-ba89-5259519fce65.png)
  4. IEvangelist revised this gist Sep 26, 2017. 1 changed file with 9 additions and 7 deletions.
    16 changes: 9 additions & 7 deletions smallest.md
    Original file line number Diff line number Diff line change
    @@ -1,8 +1,10 @@
    using Microsoft.AspNetCore;
    using Microsoft.AspNetCore.Hosting;
    using Microsoft.AspNetCore.Http;
    ```csharp
    using Microsoft.AspNetCore;
    using Microsoft.AspNetCore.Hosting;
    using Microsoft.AspNetCore.Http;

    public class Program
    {
    static void Main() => WebHost.Start(ctx => ctx.Response.WriteAsync("Hello World!")).WaitForShutdown();
    }
    public class Program
    {
    static void Main() => WebHost.Start(ctx => ctx.Response.WriteAsync("Hello World!")).WaitForShutdown();
    }
    ```
  5. IEvangelist revised this gist Sep 26, 2017. 1 changed file with 7 additions and 7 deletions.
    14 changes: 7 additions & 7 deletions smallest.md
    Original file line number Diff line number Diff line change
    @@ -1,8 +1,8 @@
    using Microsoft.AspNetCore;
    using Microsoft.AspNetCore.Hosting;
    using Microsoft.AspNetCore.Http;
    using Microsoft.AspNetCore;
    using Microsoft.AspNetCore.Hosting;
    using Microsoft.AspNetCore.Http;

    public class Program
    {
    static void Main() => WebHost.Start(ctx => ctx.Response.WriteAsync("Hello World!")).WaitForShutdown();
    }
    public class Program
    {
    static void Main() => WebHost.Start(ctx => ctx.Response.WriteAsync("Hello World!")).WaitForShutdown();
    }
  6. IEvangelist created this gist Sep 26, 2017.
    8 changes: 8 additions & 0 deletions smallest.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    using Microsoft.AspNetCore;
    using Microsoft.AspNetCore.Hosting;
    using Microsoft.AspNetCore.Http;

    public class Program
    {
    static void Main() => WebHost.Start(ctx => ctx.Response.WriteAsync("Hello World!")).WaitForShutdown();
    }