upgrade to dotnet 8

This commit is contained in:
marcel-dempers 2025-02-13 18:05:12 +11:00
parent c5c755b2c7
commit 9c289a54da
4 changed files with 49 additions and 37 deletions

View File

@ -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"]

View File

@ -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<HostOptions>(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<Startup>();
}
}
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();

View File

@ -1,9 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}

13
c#/src/helloworld.csproj Normal file
View File

@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
</ItemGroup>
</Project>