From 9c289a54da3463aa3a74881a469b1002d644d68f Mon Sep 17 00:00:00 2001 From: marcel-dempers Date: Thu, 13 Feb 2025 18:05:12 +1100 Subject: [PATCH] upgrade to dotnet 8 --- c#/dockerfile | 25 ++++++++--------- c#/src/Program.cs | 43 +++++++++++++++-------------- c#/src/appsettings.Development.json | 5 ++-- c#/src/helloworld.csproj | 13 +++++++++ 4 files changed, 49 insertions(+), 37 deletions(-) create mode 100644 c#/src/helloworld.csproj diff --git a/c#/dockerfile b/c#/dockerfile index 5b5a921..b5d3826 100644 --- a/c#/dockerfile +++ b/c#/dockerfile @@ -1,28 +1,27 @@ -FROM mcr.microsoft.com/dotnet/core/sdk:2.2-stretch as debug +FROM mcr.microsoft.com/dotnet/sdk:8.0 as build #install debugger for NET Core RUN apt-get update RUN apt-get install -y unzip RUN curl -sSL https://aka.ms/getvsdbgsh | /bin/sh /dev/stdin -v latest -l ~/vsdbg -RUN mkdir /work/ -WORKDIR /work/ +RUN mkdir /src/ +WORKDIR /src/ -COPY ./src/work.csproj /work/work.csproj +COPY ./src/helloworld.csproj /src/helloworld.csproj RUN dotnet restore -COPY ./src/ /work/ +COPY ./src/ /src/ RUN mkdir /out/ -RUN dotnet publish --no-restore --output /out/ --configuration Release + +RUN dotnet build helloworld.csproj --configuration Debug --no-restore +RUN dotnet publish helloworld.csproj --output /out --configuration Debug --no-restore ENTRYPOINT ["dotnet", "run"] -###########START NEW IMAGE########################################### +FROM mcr.microsoft.com/dotnet/aspnet:8.0 as runtime -FROM mcr.microsoft.com/dotnet/core/aspnet:2.2-stretch-slim as prod +WORKDIR /app +COPY --from=build /out/ /app -RUN mkdir /app/ -WORKDIR /app/ -COPY --from=debug /out/ /app/ -RUN chmod +x /app/ -CMD dotnet work.dll +ENTRYPOINT ["dotnet", "helloworld.dll"] diff --git a/c#/src/Program.cs b/c#/src/Program.cs index 79410b4..d54650f 100644 --- a/c#/src/Program.cs +++ b/c#/src/Program.cs @@ -1,25 +1,26 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore; using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.Logging; -namespace work +var builder = WebApplication.CreateBuilder(args); + +builder.Services.AddEndpointsApiExplorer(); +builder.Services.AddSwaggerGen(); +builder.Services.Configure(builder.Configuration.GetSection("HostOptions")); + +builder.WebHost.ConfigureKestrel(serverOptions => { - public class Program - { - public static void Main(string[] args) - { - CreateWebHostBuilder(args).Build().Run(); - } + serverOptions.ListenAnyIP(5000); +}); - public static IWebHostBuilder CreateWebHostBuilder(string[] args) => - WebHost.CreateDefaultBuilder(args) - .UseUrls("http://*:5000") - .UseStartup(); - } -} +var app = builder.Build(); + +Console.WriteLine(Environment.ProcessorCount.ToString()); + +app.UseHttpsRedirection(); + +app.MapGet("/", async () => +{ + await Task.Delay(40000); // Sleep for 40 seconds + return "Hello World!"; +}); + +app.Run(); \ No newline at end of file diff --git a/c#/src/appsettings.Development.json b/c#/src/appsettings.Development.json index a2880cb..ff66ba6 100644 --- a/c#/src/appsettings.Development.json +++ b/c#/src/appsettings.Development.json @@ -1,9 +1,8 @@ { "Logging": { "LogLevel": { - "Default": "Debug", - "System": "Information", - "Microsoft": "Information" + "Default": "Information", + "Microsoft.AspNetCore": "Warning" } } } diff --git a/c#/src/helloworld.csproj b/c#/src/helloworld.csproj new file mode 100644 index 0000000..2bd17e5 --- /dev/null +++ b/c#/src/helloworld.csproj @@ -0,0 +1,13 @@ + + + + net8.0 + enable + enable + + + + + + +