From 3c9782825040b7c6ef4d36e4c60755d3cf7a2282 Mon Sep 17 00:00:00 2001 From: Richard Lander Date: Tue, 11 Jul 2023 15:09:41 -0700 Subject: [PATCH 01/49] Update dotnetapp sample to .NET 8 --- samples/aspnetapp/Dockerfile | 14 ++++--- samples/aspnetapp/aspnetapp/aspnetapp.csproj | 3 +- samples/dotnetapp/Dockerfile | 12 +++--- samples/dotnetapp/Dockerfile.alpine | 10 +++-- samples/dotnetapp/Dockerfile.alpine-icu | 11 +++--- samples/dotnetapp/Dockerfile.alpine-slim | 10 +++-- samples/dotnetapp/Dockerfile.chiseled | 10 +++-- samples/dotnetapp/Dockerfile.debian | 9 +++-- samples/dotnetapp/Dockerfile.nanoserver | 9 ++--- samples/dotnetapp/Dockerfile.nanoserver-slim | 9 ++--- samples/dotnetapp/Dockerfile.ubuntu | 10 +++-- .../dotnetapp/Dockerfile.windowsservercore | 9 +++-- samples/dotnetapp/Program.cs | 38 +++++-------------- samples/dotnetapp/dotnetapp.csproj | 3 +- 14 files changed, 75 insertions(+), 82 deletions(-) diff --git a/samples/aspnetapp/Dockerfile b/samples/aspnetapp/Dockerfile index 36050e1f55..df22c3eb58 100644 --- a/samples/aspnetapp/Dockerfile +++ b/samples/aspnetapp/Dockerfile @@ -1,19 +1,21 @@ # Learn about building .NET container images: # https://github.com/dotnet/dotnet-docker/blob/main/samples/README.md -FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build +FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:8.0-preview AS build +ARG TARGETARCH WORKDIR /source # copy csproj and restore as distinct layers COPY aspnetapp/*.csproj . -RUN dotnet restore --use-current-runtime +RUN dotnet restore -a $TARGETARCH -# copy everything else and build app +# copy and publish app and libraries COPY aspnetapp/. . -RUN dotnet publish --use-current-runtime --self-contained false --no-restore -o /app +RUN dotnet publish -a $TARGETARCH --no-restore -o /app # final stage/image -FROM mcr.microsoft.com/dotnet/aspnet:7.0 +FROM mcr.microsoft.com/dotnet/aspnet:8.0-preview WORKDIR /app COPY --from=build /app . -ENTRYPOINT ["dotnet", "aspnetapp.dll"] +USER $APP_UID +ENTRYPOINT ["./aspnetapp"] diff --git a/samples/aspnetapp/aspnetapp/aspnetapp.csproj b/samples/aspnetapp/aspnetapp/aspnetapp.csproj index ac48ba8dd5..a38e31b7bd 100644 --- a/samples/aspnetapp/aspnetapp/aspnetapp.csproj +++ b/samples/aspnetapp/aspnetapp/aspnetapp.csproj @@ -1,11 +1,10 @@ - net7.0 + net8.0 enable enable 57393389627611478466 - true diff --git a/samples/dotnetapp/Dockerfile b/samples/dotnetapp/Dockerfile index c3ed9047d9..d2989cc928 100644 --- a/samples/dotnetapp/Dockerfile +++ b/samples/dotnetapp/Dockerfile @@ -1,19 +1,21 @@ # Learn about building .NET container images: # https://github.com/dotnet/dotnet-docker/blob/main/samples/README.md -FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build +FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:8.0-preview AS build +ARG TARGETARCH WORKDIR /source # copy csproj and restore as distinct layers COPY *.csproj . -RUN dotnet restore --use-current-runtime +RUN dotnet restore -a $TARGETARCH # copy and publish app and libraries COPY . . -RUN dotnet publish --use-current-runtime --self-contained false --no-restore -o /app +RUN dotnet publish -a $TARGETARCH --no-restore -o /app # final stage/image -FROM mcr.microsoft.com/dotnet/runtime:7.0 +FROM mcr.microsoft.com/dotnet/runtime:8.0-preview WORKDIR /app COPY --from=build /app . -ENTRYPOINT ["dotnet", "dotnetapp.dll"] +USER $APP_UID +ENTRYPOINT ["./dotnetapp"] diff --git a/samples/dotnetapp/Dockerfile.alpine b/samples/dotnetapp/Dockerfile.alpine index d01f33df1b..8f84e7ce49 100644 --- a/samples/dotnetapp/Dockerfile.alpine +++ b/samples/dotnetapp/Dockerfile.alpine @@ -1,21 +1,23 @@ # Learn about building .NET container images: # https://github.com/dotnet/dotnet-docker/blob/main/samples/README.md -FROM mcr.microsoft.com/dotnet/sdk:7.0-alpine AS build +FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:8.0-preview-alpine AS build +ARG TARGETARCH WORKDIR /source # copy csproj and restore as distinct layers COPY *.csproj . -RUN dotnet restore --use-current-runtime +RUN dotnet restore -a $TARGETARCH # copy and publish app and libraries COPY . . -RUN dotnet publish --use-current-runtime --self-contained false --no-restore -o /app +RUN dotnet publish -a $TARGETARCH --no-restore -o /app # Enable globalization and time zones: # https://github.com/dotnet/dotnet-docker/blob/main/samples/enable-globalization.md # final stage/image -FROM mcr.microsoft.com/dotnet/runtime:7.0-alpine +FROM mcr.microsoft.com/dotnet/runtime:8.0-preview-alpine WORKDIR /app COPY --from=build /app . +USER $APP_UID ENTRYPOINT ["./dotnetapp"] diff --git a/samples/dotnetapp/Dockerfile.alpine-icu b/samples/dotnetapp/Dockerfile.alpine-icu index 6c5f5f293b..f7cd07f601 100644 --- a/samples/dotnetapp/Dockerfile.alpine-icu +++ b/samples/dotnetapp/Dockerfile.alpine-icu @@ -1,21 +1,21 @@ # Learn about building .NET container images: # https://github.com/dotnet/dotnet-docker/blob/main/samples/README.md -FROM mcr.microsoft.com/dotnet/sdk:7.0-alpine AS build +FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:8.0-preview-alpine AS build +ARG TARGETARCH WORKDIR /source # copy csproj and restore as distinct layers COPY *.csproj . -RUN dotnet restore --use-current-runtime +RUN dotnet restore -a $TARGETARCH # copy and publish app and libraries COPY . . -RUN dotnet publish --use-current-runtime --self-contained false --no-restore -o /app - +RUN dotnet publish -a $TARGETARCH --no-restore -o /app # Enable globalization and time zones: # https://github.com/dotnet/dotnet-docker/blob/main/samples/enable-globalization.md # final stage/image -FROM mcr.microsoft.com/dotnet/runtime:7.0-alpine +FROM mcr.microsoft.com/dotnet/runtime:8.0-preview-alpine ENV \ DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=false \ @@ -27,4 +27,5 @@ RUN apk add --no-cache \ WORKDIR /app COPY --from=build /app . +USER $APP_UID ENTRYPOINT ["./dotnetapp"] diff --git a/samples/dotnetapp/Dockerfile.alpine-slim b/samples/dotnetapp/Dockerfile.alpine-slim index 718116d063..4192227a81 100644 --- a/samples/dotnetapp/Dockerfile.alpine-slim +++ b/samples/dotnetapp/Dockerfile.alpine-slim @@ -1,21 +1,23 @@ # Learn about building .NET container images: # https://github.com/dotnet/dotnet-docker/blob/main/samples/README.md -FROM mcr.microsoft.com/dotnet/sdk:7.0-alpine AS build +FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:8.0-preview-alpine AS build +ARG TARGETARCH WORKDIR /source # copy csproj and restore as distinct layers COPY *.csproj . -RUN dotnet restore --use-current-runtime /p:PublishReadyToRun=true +RUN dotnet restore -a $TARGETARCH /p:PublishReadyToRun=true # copy and publish app and libraries COPY . . -RUN dotnet publish --use-current-runtime --self-contained true --no-restore -o /app /p:PublishTrimmed=true /p:PublishReadyToRun=true +RUN dotnet publish -a $TARGETARCH --self-contained true --no-restore -o /app /p:PublishTrimmed=true /p:PublishReadyToRun=true # Enable globalization and time zones: # https://github.com/dotnet/dotnet-docker/blob/main/samples/enable-globalization.md # final stage/image -FROM mcr.microsoft.com/dotnet/runtime-deps:7.0-alpine +FROM mcr.microsoft.com/dotnet/runtime-deps:8.0-preview-alpine WORKDIR /app COPY --from=build /app . +USER $APP_UID ENTRYPOINT ["./dotnetapp"] diff --git a/samples/dotnetapp/Dockerfile.chiseled b/samples/dotnetapp/Dockerfile.chiseled index ef71485ef1..4c74b977f1 100644 --- a/samples/dotnetapp/Dockerfile.chiseled +++ b/samples/dotnetapp/Dockerfile.chiseled @@ -1,19 +1,21 @@ # Learn about building .NET container images: # https://github.com/dotnet/dotnet-docker/blob/main/samples/README.md -FROM mcr.microsoft.com/dotnet/sdk:7.0-jammy AS build +FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:8.0-preview-jammy AS build +ARG TARGETARCH WORKDIR /source # copy csproj and restore as distinct layers COPY *.csproj . -RUN dotnet restore --use-current-runtime +RUN dotnet restore -a $TARGETARCH # copy and publish app and libraries COPY . . -RUN dotnet publish --use-current-runtime --self-contained false --no-restore -o /app +RUN dotnet publish -a $TARGETARCH --no-restore -o /app # final stage/image -FROM mcr.microsoft.com/dotnet/nightly/runtime:7.0-jammy-chiseled +FROM mcr.microsoft.com/dotnet/runtime:8.0-preview-jammy-chiseled WORKDIR /app COPY --from=build /app . +USER $APP_UID ENTRYPOINT ["./dotnetapp"] diff --git a/samples/dotnetapp/Dockerfile.debian b/samples/dotnetapp/Dockerfile.debian index 845bbbc327..9e77b3884e 100644 --- a/samples/dotnetapp/Dockerfile.debian +++ b/samples/dotnetapp/Dockerfile.debian @@ -1,20 +1,21 @@ # Learn about building .NET container images: # https://github.com/dotnet/dotnet-docker/blob/main/samples/README.md -FROM mcr.microsoft.com/dotnet/sdk:7.0-bullseye-slim AS build +FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:8.0-preview-bookworm-slim AS build ARG TARGETARCH WORKDIR /source # copy csproj and restore as distinct layers COPY *.csproj . -RUN dotnet restore --use-current-runtime +RUN dotnet restore -a $TARGETARCH # copy and publish app and libraries COPY . . -RUN dotnet publish --use-current-runtime --self-contained false --no-restore -o /app +RUN dotnet publish -a $TARGETARCH --no-restore -o /app # final stage/image -FROM mcr.microsoft.com/dotnet/runtime:7.0-bullseye-slim +FROM mcr.microsoft.com/dotnet/runtime:8.0-preview-bookworm-slim WORKDIR /app COPY --from=build /app . +USER $APP_UID ENTRYPOINT ["./dotnetapp"] diff --git a/samples/dotnetapp/Dockerfile.nanoserver b/samples/dotnetapp/Dockerfile.nanoserver index 0c9b2843e5..5b1c5cada3 100644 --- a/samples/dotnetapp/Dockerfile.nanoserver +++ b/samples/dotnetapp/Dockerfile.nanoserver @@ -1,20 +1,19 @@ # escape=` # Learn about building .NET container images: # https://github.com/dotnet/dotnet-docker/blob/main/samples/README.md -ARG TAG=ltsc2022 -FROM mcr.microsoft.com/dotnet/sdk:7.0-nanoserver-$TAG AS build +FROM mcr.microsoft.com/dotnet/sdk:8.0-preview-nanoserver-ltsc2022 AS build WORKDIR /source # copy csproj and restore as distinct layers COPY *.csproj . -RUN dotnet restore -r win-x64 +RUN dotnet restore --ucr # copy and publish app and libraries COPY . . -RUN dotnet publish -c Release -o /app -r win-x64 --self-contained false --no-restore +RUN dotnet publish --ucr --no-restore -o /app # final stage/image -FROM mcr.microsoft.com/dotnet/runtime:7.0-nanoserver-$TAG +FROM mcr.microsoft.com/dotnet/runtime:8.0-preview-nanoserver-ltsc2022 WORKDIR /app COPY --from=build /app . ENTRYPOINT ["dotnetapp"] diff --git a/samples/dotnetapp/Dockerfile.nanoserver-slim b/samples/dotnetapp/Dockerfile.nanoserver-slim index d558990558..f6b19efbde 100644 --- a/samples/dotnetapp/Dockerfile.nanoserver-slim +++ b/samples/dotnetapp/Dockerfile.nanoserver-slim @@ -1,20 +1,19 @@ # escape=` # Learn about building .NET container images: # https://github.com/dotnet/dotnet-docker/blob/main/samples/README.md -ARG TAG=ltsc2022 -FROM mcr.microsoft.com/dotnet/sdk:7.0-nanoserver-$TAG AS build +FROM mcr.microsoft.com/dotnet/sdk:8.0-preview-nanoserver-ltsc2022 AS build WORKDIR /source # copy csproj and restore as distinct layers COPY *.csproj . -RUN dotnet restore --use-current-runtime /p:PublishReadyToRun=true +RUN dotnet restore --ucr /p:PublishReadyToRun=true # copy and publish app and libraries COPY . . -RUN dotnet publish --use-current-runtime --self-contained true --no-restore -o /app /p:PublishTrimmed=true /p:PublishReadyToRun=true +RUN dotnet publish --ucr --self-contained true --no-restore -o /app /p:PublishTrimmed=true /p:PublishReadyToRun=true # final stage/image -FROM mcr.microsoft.com/windows/nanoserver:$TAG +FROM mcr.microsoft.com/windows/nanoserver:ltsc2022 WORKDIR /app COPY --from=build /app . diff --git a/samples/dotnetapp/Dockerfile.ubuntu b/samples/dotnetapp/Dockerfile.ubuntu index a19e89f373..4655db9c50 100644 --- a/samples/dotnetapp/Dockerfile.ubuntu +++ b/samples/dotnetapp/Dockerfile.ubuntu @@ -1,19 +1,21 @@ # Learn about building .NET container images: # https://github.com/dotnet/dotnet-docker/blob/main/samples/README.md -FROM mcr.microsoft.com/dotnet/sdk:7.0-jammy AS build +FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:8.0-preview-jammy AS build +ARG TARGETARCH WORKDIR /source # copy csproj and restore as distinct layers COPY *.csproj . -RUN dotnet restore --use-current-runtime +RUN dotnet restore -a $TARGETARCH # copy and publish app and libraries COPY . . -RUN dotnet publish --use-current-runtime --self-contained false --no-restore -o /app +RUN dotnet publish -a $TARGETARCH --no-restore -o /app # final stage/image -FROM mcr.microsoft.com/dotnet/runtime:7.0-jammy +FROM mcr.microsoft.com/dotnet/runtime:8.0-preview-jammy WORKDIR /app COPY --from=build /app . +USER $APP_UID ENTRYPOINT ["./dotnetapp"] diff --git a/samples/dotnetapp/Dockerfile.windowsservercore b/samples/dotnetapp/Dockerfile.windowsservercore index 26c33318ca..40b648d59e 100644 --- a/samples/dotnetapp/Dockerfile.windowsservercore +++ b/samples/dotnetapp/Dockerfile.windowsservercore @@ -1,18 +1,19 @@ # Learn about building .NET container images: # https://github.com/dotnet/dotnet-docker/blob/main/samples/README.md -FROM mcr.microsoft.com/dotnet/sdk:7.0-windowsservercore-ltsc2022 AS build +FROM mcr.microsoft.com/dotnet/sdk:8.0-preview-windowsservercore-ltsc2022 AS build WORKDIR /source # copy csproj and restore as distinct layers COPY *.csproj . -RUN dotnet restore --use-current-runtime +RUN dotnet restore --ucr # copy and publish app and libraries COPY . . -RUN dotnet publish --use-current-runtime --self-contained false --no-restore -o /app +RUN dotnet publish --ucr --no-restore -o /app # final stage/image -FROM mcr.microsoft.com/dotnet/runtime:7.0-windowsservercore-ltsc2022 +FROM mcr.microsoft.com/dotnet/runtime:8.0-preview-windowsservercore-ltsc2022 WORKDIR /app COPY --from=build /app . +USER ContainerUser ENTRYPOINT ["dotnetapp"] diff --git a/samples/dotnetapp/Program.cs b/samples/dotnetapp/Program.cs index 70e445f121..fd26d2d280 100644 --- a/samples/dotnetapp/Program.cs +++ b/samples/dotnetapp/Program.cs @@ -20,43 +20,25 @@ 8b 42 8b d8 42 42 42 8PP!!!!!!! 42 """); -// .NET information -WriteLine(RuntimeInformation.FrameworkDescription); - -// OS information -const string OSRel = "/etc/os-release"; -if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) && - File.Exists(OSRel)) -{ - const string PrettyName = "PRETTY_NAME"; - foreach(string line in File.ReadAllLines(OSRel)) - { - if (line.StartsWith(PrettyName)) - { - ReadOnlySpan value = line.AsSpan()[(PrettyName.Length + 2)..^1]; - WriteLine(value.ToString()); - break; - } - } -} -else -{ - WriteLine(RuntimeInformation.OSDescription); -} - -WriteLine(); - const long Mebi = 1024 * 1024; const long Gibi = Mebi * 1024; GCMemoryInfo gcInfo = GC.GetGCMemoryInfo(); long totalMemoryBytes = gcInfo.TotalAvailableMemoryBytes; +// OS and .NET information +WriteLine($"{nameof(RuntimeInformation.OSArchitecture)}: {RuntimeInformation.OSArchitecture}"); +WriteLine($"{nameof(RuntimeInformation.OSDescription)}: {RuntimeInformation.OSDescription}"); +WriteLine($"{nameof(RuntimeInformation.FrameworkDescription)}: {RuntimeInformation.FrameworkDescription}"); +WriteLine(); + // Environment information WriteLine($"{nameof(Environment.UserName)}: {Environment.UserName}"); -WriteLine($"{nameof(RuntimeInformation.OSArchitecture)}: {RuntimeInformation.OSArchitecture}"); +WriteLine($"HostName : {Dns.GetHostName()}"); +WriteLine(); + +// Hardware information WriteLine($"{nameof(Environment.ProcessorCount)}: {Environment.ProcessorCount}"); WriteLine($"{nameof(GCMemoryInfo.TotalAvailableMemoryBytes)}: {totalMemoryBytes} ({GetInBestUnit(totalMemoryBytes)})"); -WriteLine($"HostName : {Dns.GetHostName()}"); string[] memoryLimitPaths = new string[] { diff --git a/samples/dotnetapp/dotnetapp.csproj b/samples/dotnetapp/dotnetapp.csproj index aa077a0f83..6370f55af4 100644 --- a/samples/dotnetapp/dotnetapp.csproj +++ b/samples/dotnetapp/dotnetapp.csproj @@ -2,9 +2,8 @@ Exe - net7.0 + net8.0 enable - true From a0a73f8e32a98bc4ad5c3427639345533660845d Mon Sep 17 00:00:00 2001 From: Richard Lander Date: Tue, 11 Jul 2023 16:33:18 -0700 Subject: [PATCH 02/49] Update ASP.NET sample --- samples/aspnetapp/Dockerfile.alpine | 13 +- samples/aspnetapp/Dockerfile.alpine-icu | 13 +- samples/aspnetapp/Dockerfile.alpine-non-root | 30 --- samples/aspnetapp/Dockerfile.alpine-slim | 12 +- samples/aspnetapp/Dockerfile.chiseled | 9 +- samples/aspnetapp/Dockerfile.debian | 10 +- samples/aspnetapp/Dockerfile.nanoserver | 9 +- samples/aspnetapp/Dockerfile.nanoserver-slim | 9 +- samples/aspnetapp/Dockerfile.ubuntu | 10 +- .../aspnetapp/Dockerfile.windowsservercore | 8 +- .../Dockerfile.windowsservercore-iis | 28 ++- samples/aspnetapp/README.md | 20 +- .../aspnetapp/Controllers/HomeController.cs | 31 --- .../aspnetapp/Models/ErrorViewModel.cs | 8 - .../{Views/Shared => Pages}/Error.cshtml | 5 +- .../aspnetapp/aspnetapp/Pages/Error.cshtml.cs | 27 +++ .../{Views/Home => Pages}/Index.cshtml | 4 +- .../aspnetapp/aspnetapp/Pages/Index.cshtml.cs | 19 ++ .../{Views/Home => Pages}/Privacy.cshtml | 4 +- .../aspnetapp/Pages/Privacy.cshtml.cs | 19 ++ .../{Views => Pages}/Shared/_Layout.cshtml | 14 +- .../Shared/_Layout.cshtml.css | 2 +- .../Shared/_ValidationScriptsPartial.cshtml | 0 .../{Views => Pages}/_ViewImports.cshtml | 2 +- .../{Views => Pages}/_ViewStart.cshtml | 0 samples/aspnetapp/aspnetapp/Program.cs | 10 +- .../aspnetapp/Properties/launchSettings.json | 11 +- .../aspnetapp/appsettings.Development.json | 1 + samples/aspnetapp/aspnetapp/aspnetapp.csproj | 1 - .../aspnetapp/aspnetapp/wwwroot/css/site.css | 4 + .../aspnetapp/aspnetapp/wwwroot/js/site.js | 2 +- .../jquery-validation-unobtrusive/LICENSE.txt | 29 ++- .../jquery.validate.unobtrusive.js | 11 +- .../jquery.validate.unobtrusive.min.js | 13 +- .../aspnetapp/wwwroot/lib/jquery/LICENSE.txt | 19 +- .../wwwroot/lib/jquery/dist/jquery.js | 227 +++++++++--------- .../wwwroot/lib/jquery/dist/jquery.min.js | 4 +- .../wwwroot/lib/jquery/dist/jquery.min.map | 2 +- samples/dotnetapp/Dockerfile.chiseled | 1 - 39 files changed, 333 insertions(+), 308 deletions(-) delete mode 100644 samples/aspnetapp/Dockerfile.alpine-non-root delete mode 100644 samples/aspnetapp/aspnetapp/Controllers/HomeController.cs delete mode 100644 samples/aspnetapp/aspnetapp/Models/ErrorViewModel.cs rename samples/aspnetapp/aspnetapp/{Views/Shared => Pages}/Error.cshtml (82%) create mode 100644 samples/aspnetapp/aspnetapp/Pages/Error.cshtml.cs rename samples/aspnetapp/aspnetapp/{Views/Home => Pages}/Index.cshtml (97%) create mode 100644 samples/aspnetapp/aspnetapp/Pages/Index.cshtml.cs rename samples/aspnetapp/aspnetapp/{Views/Home => Pages}/Privacy.cshtml (80%) create mode 100644 samples/aspnetapp/aspnetapp/Pages/Privacy.cshtml.cs rename samples/aspnetapp/aspnetapp/{Views => Pages}/Shared/_Layout.cshtml (83%) rename samples/aspnetapp/aspnetapp/{Views => Pages}/Shared/_Layout.cshtml.css (87%) rename samples/aspnetapp/aspnetapp/{Views => Pages}/Shared/_ValidationScriptsPartial.cshtml (100%) rename samples/aspnetapp/aspnetapp/{Views => Pages}/_ViewImports.cshtml (73%) rename samples/aspnetapp/aspnetapp/{Views => Pages}/_ViewStart.cshtml (100%) diff --git a/samples/aspnetapp/Dockerfile.alpine b/samples/aspnetapp/Dockerfile.alpine index 85b4b31aab..ceca5eac88 100644 --- a/samples/aspnetapp/Dockerfile.alpine +++ b/samples/aspnetapp/Dockerfile.alpine @@ -1,22 +1,23 @@ # Learn about building .NET container images: # https://github.com/dotnet/dotnet-docker/blob/main/samples/README.md -FROM mcr.microsoft.com/dotnet/sdk:7.0-alpine AS build - +FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:8.0-preview-alpine AS build +ARG TARGETARCH WORKDIR /source # copy csproj and restore as distinct layers COPY aspnetapp/*.csproj . -RUN dotnet restore --use-current-runtime +RUN dotnet restore -a $TARGETARCH -# copy everything else and build app +# copy and publish app and libraries COPY aspnetapp/. . -RUN dotnet publish --use-current-runtime --self-contained false --no-restore -o /app +RUN dotnet publish -a $TARGETARCH --no-restore -o /app # Enable globalization and time zones: # https://github.com/dotnet/dotnet-docker/blob/main/samples/enable-globalization.md # final stage/image -FROM mcr.microsoft.com/dotnet/aspnet:7.0-alpine +FROM mcr.microsoft.com/dotnet/aspnet:8.0-preview-alpine WORKDIR /app COPY --from=build /app . +USER $APP_UID ENTRYPOINT ["./aspnetapp"] diff --git a/samples/aspnetapp/Dockerfile.alpine-icu b/samples/aspnetapp/Dockerfile.alpine-icu index 08f50de9e0..9ff1ceef0f 100644 --- a/samples/aspnetapp/Dockerfile.alpine-icu +++ b/samples/aspnetapp/Dockerfile.alpine-icu @@ -1,22 +1,22 @@ # Learn about building .NET container images: # https://github.com/dotnet/dotnet-docker/blob/main/samples/README.md -FROM mcr.microsoft.com/dotnet/sdk:7.0-alpine AS build - +FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:8.0-preview-alpine AS build +ARG TARGETARCH WORKDIR /source # copy csproj and restore as distinct layers COPY aspnetapp/*.csproj . -RUN dotnet restore --use-current-runtime +RUN dotnet restore -a $TARGETARCH -# copy everything else and build app +# copy and publish app and libraries COPY aspnetapp/. . -RUN dotnet publish --use-current-runtime --self-contained false --no-restore -o /app +RUN dotnet publish -a $TARGETARCH --no-restore -o /app # Enable globalization and time zones: # https://github.com/dotnet/dotnet-docker/blob/main/samples/enable-globalization.md # final stage/image -FROM mcr.microsoft.com/dotnet/aspnet:7.0-alpine +FROM mcr.microsoft.com/dotnet/aspnet:8.0-preview-alpine ENV \ DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=false \ @@ -28,4 +28,5 @@ RUN apk add --no-cache \ WORKDIR /app COPY --from=build /app . +USER $APP_UID ENTRYPOINT ["./aspnetapp"] diff --git a/samples/aspnetapp/Dockerfile.alpine-non-root b/samples/aspnetapp/Dockerfile.alpine-non-root deleted file mode 100644 index 037f6f48a0..0000000000 --- a/samples/aspnetapp/Dockerfile.alpine-non-root +++ /dev/null @@ -1,30 +0,0 @@ -# Learn about building .NET container images: -# https://github.com/dotnet/dotnet-docker/blob/main/samples/README.md -FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:8.0-preview-alpine AS build -ARG TARGETARCH -WORKDIR /source - -# copy csproj and restore as distinct layers -COPY aspnetapp/*.csproj . -RUN dotnet restore -a $TARGETARCH - -# copy everything else and build app -COPY aspnetapp/. . -RUN dotnet publish -a $TARGETARCH --no-restore -o /app - - -# Enable globalization and time zones: -# https://github.com/dotnet/dotnet-docker/blob/main/samples/enable-globalization.md -# final stage/image -# .NET 8 tag includes `-preview` -FROM mcr.microsoft.com/dotnet/aspnet:8.0-preview-alpine - -# These ENVs are only needed because the sample uses .NET 7 -ENV DOTNET_ROLL_FORWARD=Major -ENV DOTNET_ROLL_FORWARD_PRE_RELEASE=1 - -WORKDIR /app -COPY --from=build /app . - -USER $APP_UID -ENTRYPOINT ["./aspnetapp"] diff --git a/samples/aspnetapp/Dockerfile.alpine-slim b/samples/aspnetapp/Dockerfile.alpine-slim index c0734f8095..ae3bb9f486 100644 --- a/samples/aspnetapp/Dockerfile.alpine-slim +++ b/samples/aspnetapp/Dockerfile.alpine-slim @@ -1,24 +1,26 @@ # Learn about building .NET container images: # https://github.com/dotnet/dotnet-docker/blob/main/samples/README.md -FROM mcr.microsoft.com/dotnet/sdk:7.0-alpine AS build +FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:8.0-preview-alpine AS build +ARG TARGETARCH WORKDIR /source # copy csproj and restore as distinct layers COPY aspnetapp/*.csproj . -RUN dotnet restore --use-current-runtime /p:PublishReadyToRun=true +RUN dotnet restore -a $TARGETARCH /p:PublishReadyToRun=true # copy everything else and build app COPY aspnetapp/. . -RUN dotnet publish --use-current-runtime --no-restore -o /app /p:PublishTrimmed=true /p:PublishReadyToRun=true +RUN dotnet publish -a $TARGETARCH --no-restore --self-contained -o /app /p:PublishTrimmed=true /p:PublishReadyToRun=true # Enable globalization and time zones: # https://github.com/dotnet/dotnet-docker/blob/main/samples/enable-globalization.md # final stage/image -FROM mcr.microsoft.com/dotnet/runtime-deps:7.0-alpine +FROM mcr.microsoft.com/dotnet/runtime-deps:8.0-preview-alpine WORKDIR /app COPY --from=build /app . # This port needs to match the port being used -HEALTHCHECK CMD wget -qO- -t1 http://localhost:80/healthz || exit 1 +HEALTHCHECK CMD wget -qO- -t1 http://localhost:8080/healthz || exit 1 +USER $APP_UID ENTRYPOINT ["./aspnetapp"] diff --git a/samples/aspnetapp/Dockerfile.chiseled b/samples/aspnetapp/Dockerfile.chiseled index f4735a973f..89756a6806 100644 --- a/samples/aspnetapp/Dockerfile.chiseled +++ b/samples/aspnetapp/Dockerfile.chiseled @@ -1,19 +1,20 @@ # Learn about building .NET container images: # https://github.com/dotnet/dotnet-docker/blob/main/samples/README.md -FROM mcr.microsoft.com/dotnet/sdk:7.0-jammy AS build +FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:8.0-preview-jammy AS build +ARG TARGETARCH WORKDIR /source # copy csproj and restore as distinct layers COPY aspnetapp/*.csproj . -RUN dotnet restore --use-current-runtime +RUN dotnet restore -a $TARGETARCH # copy everything else and build app COPY aspnetapp/. . -RUN dotnet publish --use-current-runtime --self-contained false --no-restore -o /app +RUN dotnet publish -a $TARGETARCH --no-restore -o /app # final stage/image -FROM mcr.microsoft.com/dotnet/nightly/aspnet:7.0-jammy-chiseled +FROM mcr.microsoft.com/dotnet/aspnet:8.0-preview-jammy-chiseled WORKDIR /app COPY --from=build /app . ENTRYPOINT ["./aspnetapp"] diff --git a/samples/aspnetapp/Dockerfile.debian b/samples/aspnetapp/Dockerfile.debian index 53de577a22..279e82f5f7 100644 --- a/samples/aspnetapp/Dockerfile.debian +++ b/samples/aspnetapp/Dockerfile.debian @@ -1,19 +1,21 @@ # Learn about building .NET container images: # https://github.com/dotnet/dotnet-docker/blob/main/samples/README.md -FROM mcr.microsoft.com/dotnet/sdk:7.0-bullseye-slim AS build +FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:8.0-preview-bookworm-slim AS build +ARG TARGETARCH WORKDIR /source # copy csproj and restore as distinct layers COPY aspnetapp/*.csproj . -RUN dotnet restore --use-current-runtime +RUN dotnet restore -a $TARGETARCH # copy everything else and build app COPY aspnetapp/. . -RUN dotnet publish --use-current-runtime --self-contained false --no-restore -o /app +RUN dotnet publish -a $TARGETARCH --no-restore -o /app # final stage/image -FROM mcr.microsoft.com/dotnet/aspnet:7.0-bullseye-slim +FROM mcr.microsoft.com/dotnet/aspnet:8.0-preview-bookworm-slim WORKDIR /app COPY --from=build /app . +USER $APP_UID ENTRYPOINT ["./aspnetapp"] diff --git a/samples/aspnetapp/Dockerfile.nanoserver b/samples/aspnetapp/Dockerfile.nanoserver index a5cd60efd9..4cd87a40d7 100644 --- a/samples/aspnetapp/Dockerfile.nanoserver +++ b/samples/aspnetapp/Dockerfile.nanoserver @@ -1,21 +1,20 @@ # escape=` # Learn about building .NET container images: # https://github.com/dotnet/dotnet-docker/blob/main/samples/README.md -ARG TAG=ltsc2022 -FROM mcr.microsoft.com/dotnet/sdk:7.0-nanoserver-$TAG AS build +FROM mcr.microsoft.com/dotnet/sdk:8.0-preview-nanoserver-ltsc2022 AS build WORKDIR /source # copy csproj and restore as distinct layers COPY aspnetapp/*.csproj . -RUN dotnet restore --use-current-runtime +RUN dotnet restore --ucr # copy everything else and build app COPY aspnetapp/. . -RUN dotnet publish --use-current-runtime --no-restore -o /app +RUN dotnet publish --ucr --no-restore -o /app # final stage/image -FROM mcr.microsoft.com/dotnet/aspnet:7.0-nanoserver-$TAG +FROM mcr.microsoft.com/dotnet/aspnet:8.0-preview-nanoserver-ltsc2022 WORKDIR /app COPY --from=build /app . HEALTHCHECK CMD curl -sf --show-error http://localhost:80/healthz || exit 1 diff --git a/samples/aspnetapp/Dockerfile.nanoserver-slim b/samples/aspnetapp/Dockerfile.nanoserver-slim index 282c8d1b88..6fcc766e4f 100644 --- a/samples/aspnetapp/Dockerfile.nanoserver-slim +++ b/samples/aspnetapp/Dockerfile.nanoserver-slim @@ -1,21 +1,20 @@ # escape=` # Learn about building .NET container images: # https://github.com/dotnet/dotnet-docker/blob/main/samples/README.md -ARG TAG=ltsc2022 -FROM mcr.microsoft.com/dotnet/sdk:7.0-nanoserver-$TAG AS build +FROM mcr.microsoft.com/dotnet/sdk:8.0-preview-nanoserver-ltsc2022 AS build WORKDIR /source # copy csproj and restore as distinct layers COPY aspnetapp/*.csproj . -RUN dotnet restore --use-current-runtime /p:PublishReadyToRun=true +RUN dotnet restore --ucr /p:PublishReadyToRun=true # copy everything else and build app COPY aspnetapp/. . -RUN dotnet publish --use-current-runtime --no-restore -o /app /p:PublishTrimmed=true /p:PublishReadyToRun=true +RUN dotnet publish --ucr --self-contained --no-restore -o /app /p:PublishTrimmed=true /p:PublishReadyToRun=true # final stage/image -FROM mcr.microsoft.com/windows/nanoserver:$TAG +FROM mcr.microsoft.com/windows/nanoserver:ltsc2022 WORKDIR /app COPY --from=build /app . HEALTHCHECK CMD curl -sf --show-error http://localhost:80/healthz || exit 1 diff --git a/samples/aspnetapp/Dockerfile.ubuntu b/samples/aspnetapp/Dockerfile.ubuntu index bddb0cda83..fc87c1e3b2 100644 --- a/samples/aspnetapp/Dockerfile.ubuntu +++ b/samples/aspnetapp/Dockerfile.ubuntu @@ -1,19 +1,21 @@ # Learn about building .NET container images: # https://github.com/dotnet/dotnet-docker/blob/main/samples/README.md -FROM mcr.microsoft.com/dotnet/sdk:7.0-jammy AS build +FROM --platform=$BUILDPLATFORM mcr.microsoft.com/dotnet/sdk:8.0-preview-jammy AS build +ARG TARGETARCH WORKDIR /source # copy csproj and restore as distinct layers COPY aspnetapp/*.csproj . -RUN dotnet restore --use-current-runtime +RUN dotnet restore -a $TARGETARCH # copy everything else and build app COPY aspnetapp/. . -RUN dotnet publish --use-current-runtime --self-contained false --no-restore -o /app +RUN dotnet publish -a $TARGETARCH --no-restore -o /app # final stage/image -FROM mcr.microsoft.com/dotnet/aspnet:7.0-jammy +FROM mcr.microsoft.com/dotnet/aspnet:8.0-preview-jammy WORKDIR /app COPY --from=build /app . +USER $APP_UID ENTRYPOINT ["./aspnetapp"] diff --git a/samples/aspnetapp/Dockerfile.windowsservercore b/samples/aspnetapp/Dockerfile.windowsservercore index fe923d915c..7584a920f2 100644 --- a/samples/aspnetapp/Dockerfile.windowsservercore +++ b/samples/aspnetapp/Dockerfile.windowsservercore @@ -1,18 +1,18 @@ # Learn about building .NET container images: # https://github.com/dotnet/dotnet-docker/blob/main/samples/README.md -FROM mcr.microsoft.com/dotnet/sdk:7.0-windowsservercore-ltsc2022 AS build +FROM mcr.microsoft.com/dotnet/sdk:8.0-preview-windowsservercore-ltsc2022 AS build WORKDIR /source # copy csproj and restore as distinct layers COPY aspnetapp/*.csproj . -RUN dotnet restore --use-current-runtime +RUN dotnet restore --ucr # copy everything else and build app COPY aspnetapp/. . -RUN dotnet publish --use-current-runtime --self-contained false --no-restore -o /app +RUN dotnet publish --ucr --no-restore -o /app # final stage/image -FROM mcr.microsoft.com/dotnet/aspnet:7.0-windowsservercore-ltsc2022 AS runtime +FROM mcr.microsoft.com/dotnet/aspnet:8.0-preview-windowsservercore-ltsc2022 WORKDIR /app COPY --from=build /app . USER ContainerUser diff --git a/samples/aspnetapp/Dockerfile.windowsservercore-iis b/samples/aspnetapp/Dockerfile.windowsservercore-iis index 910ff54bb8..d480ffd73f 100644 --- a/samples/aspnetapp/Dockerfile.windowsservercore-iis +++ b/samples/aspnetapp/Dockerfile.windowsservercore-iis @@ -1,19 +1,8 @@ # escape=` # Learn about building .NET container images: # https://github.com/dotnet/dotnet-docker/blob/main/samples/README.md -FROM mcr.microsoft.com/dotnet/sdk:7.0-windowsservercore-ltsc2022 AS build -WORKDIR /source - -# copy csproj and restore as distinct layers -COPY aspnetapp/*.csproj . -RUN dotnet restore --use-current-runtime - -# copy everything else and build app -COPY aspnetapp/. . -RUN dotnet publish --use-current-runtime --self-contained false --no-restore -o /app - # final stage/image -FROM mcr.microsoft.com/dotnet/aspnet:7.0-windowsservercore-ltsc2022 +FROM mcr.microsoft.com/dotnet/aspnet:8.0-preview-windowsservercore-ltsc2022 AS final RUN powershell -Command ` $ErrorActionPreference = 'Stop'; ` @@ -35,9 +24,22 @@ RUN powershell -Command ` Remove-Item -Force C:\dotnet-hosting-win.exe; ` Remove-Item -Force -Recurse $Env:Temp\* +FROM mcr.microsoft.com/dotnet/sdk:8.0-preview-windowsservercore-ltsc2022 AS build +WORKDIR /source + +# copy csproj and restore as distinct layers +COPY aspnetapp/*.csproj . +RUN dotnet restore --ucr + +# copy everything else and build app +COPY aspnetapp/. . +RUN dotnet publish --ucr --no-restore -o /app + + +FROM final WORKDIR /inetpub/wwwroot COPY --from=build /app . EXPOSE 80 - +USER ContainerUser ENTRYPOINT ["C:\\ServiceMonitor.exe", "w3svc"] diff --git a/samples/aspnetapp/README.md b/samples/aspnetapp/README.md index 66cc5740f5..7e89527fd7 100644 --- a/samples/aspnetapp/README.md +++ b/samples/aspnetapp/README.md @@ -7,14 +7,14 @@ This sample demonstrates how to build container images for ASP.NET Core web apps You can start by launching a sample from our [container registry](https://mcr.microsoft.com/) and access it in your web browser at `http://localhost:8000`. ```console -docker run --rm -it -p 8000:80 mcr.microsoft.com/dotnet/samples:aspnetapp +docker run --rm -it -p 8000:8080 mcr.microsoft.com/dotnet/samples:aspnetapp ``` You can also call an endpoint that the app exposes: ```bash $ curl http://localhost:8000/Environment -{"runtimeVersion":".NET 7.0.2","osVersion":"Linux 5.15.79.1-microsoft-standard-WSL2 #1 SMP Wed Nov 23 01:01:46 UTC 2022","osArchitecture":"X64","user":"root","processorCount":16,"totalAvailableMemoryBytes":67430023168,"memoryLimit":9223372036854771712,"memoryUsage":100577280} +{"runtimeVersion":".NET 8.0.0-preview.6.23329.7","osVersion":"Ubuntu 22.04.2 LTS","osArchitecture":"Arm64","user":"app","processorCount":4,"totalAvailableMemoryBytes":4124442624,"memoryLimit":0,"memoryUsage":31518720,"hostName":"78e2b2cfc0e8"} ``` ## Build an ASP.NET Core image @@ -23,29 +23,29 @@ You can build and run an image using the following instructions (if you've clone ```console docker build --pull -t aspnetapp . -docker run --rm -it -p 8000:80 aspnetapp +docker run --rm -it -p 8000:8080 aspnetapp ``` You should see the following console output as the application starts: ```console -> docker run --rm -it -p 8000:80 aspnetapp -Hosting environment: Production -Content root path: /app -Now listening on: http://[::]:80 -Application started. Press Ctrl+C to shut down. +> docker run --rm -it -p 8000:8080 aspnetapp +info: Microsoft.Hosting.Lifetime[14] + Now listening on: http://[::]:8080 +info: Microsoft.Hosting.Lifetime[0] + Application started. Press Ctrl+C to shut down. ``` After the application starts, navigate to `http://localhost:8000` in your web browser. You can also view the ASP.NET Core site running in the container from another machine with a local IP address such as `http://192.168.1.18:8000`. -> Note: ASP.NET Core apps (in our official images) listen to [port 80 by default](https://github.com/dotnet/dotnet-docker/blob/d5df3f0710c43b14aacdac1e30ceed666699ea69/src/runtime-deps/6.0/jammy/amd64/Dockerfile#L19). The [`-p` argument](https://docs.docker.com/engine/reference/commandline/run/#publish) in these examples maps host port `8000` to container port `80` (`host:container` mapping). The container will not be accessible without this mapping. ASP.NET Core can be [configured to listen on a different or additional port](https://learn.microsoft.com/aspnet/core/fundamentals/servers/kestrel/endpoints). +> Note: ASP.NET Core apps (in our official images) listen to [port 8080 by default](https://github.com/dotnet/dotnet-docker/blob/6da64f31944bb16ecde5495b6a53fc170fbe100d/src/runtime-deps/8.0/bookworm-slim/amd64/Dockerfile#L7), starting with .NET 8. The [`-p` argument](https://docs.docker.com/engine/reference/commandline/run/#publish) in these examples maps host port `8000` to container port `8080` (`host:container` mapping). The container will not be accessible without this mapping. ASP.NET Core can be [configured to listen on a different or additional port](https://learn.microsoft.com/aspnet/core/fundamentals/servers/kestrel/endpoints). You can see the app running via `docker ps`. ```bash $ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES -d79edc6bfcb6 mcr.microsoft.com/dotnet/samples:aspnetapp "./aspnetapp" 35 seconds ago Up 34 seconds (healthy) 0.0.0.0:8080->80/tcp nice_curran +d79edc6bfcb6 mcr.microsoft.com/dotnet/samples:aspnetapp "./aspnetapp" 35 seconds ago Up 34 seconds (healthy) 0.0.0.0:8080->8080/tcp nice_curran ``` You may notice that the sample includes a [health check](../enable-healthchecks.md), indicated in the "STATUS" column. diff --git a/samples/aspnetapp/aspnetapp/Controllers/HomeController.cs b/samples/aspnetapp/aspnetapp/Controllers/HomeController.cs deleted file mode 100644 index f874e8d4c2..0000000000 --- a/samples/aspnetapp/aspnetapp/Controllers/HomeController.cs +++ /dev/null @@ -1,31 +0,0 @@ -using System.Diagnostics; -using Microsoft.AspNetCore.Mvc; -using aspnetapp.Models; - -namespace aspnetapp.Controllers; - -public class HomeController : Controller -{ - private readonly ILogger _logger; - - public HomeController(ILogger logger) - { - _logger = logger; - } - - public IActionResult Index() - { - return View(); - } - - public IActionResult Privacy() - { - return View(); - } - - [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] - public IActionResult Error() - { - return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier }); - } -} diff --git a/samples/aspnetapp/aspnetapp/Models/ErrorViewModel.cs b/samples/aspnetapp/aspnetapp/Models/ErrorViewModel.cs deleted file mode 100644 index 54d8c39ebc..0000000000 --- a/samples/aspnetapp/aspnetapp/Models/ErrorViewModel.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace aspnetapp.Models; - -public class ErrorViewModel -{ - public string? RequestId { get; set; } - - public bool ShowRequestId => !string.IsNullOrEmpty(RequestId); -} diff --git a/samples/aspnetapp/aspnetapp/Views/Shared/Error.cshtml b/samples/aspnetapp/aspnetapp/Pages/Error.cshtml similarity index 82% rename from samples/aspnetapp/aspnetapp/Views/Shared/Error.cshtml rename to samples/aspnetapp/aspnetapp/Pages/Error.cshtml index a1e04783c6..6f92b95655 100644 --- a/samples/aspnetapp/aspnetapp/Views/Shared/Error.cshtml +++ b/samples/aspnetapp/aspnetapp/Pages/Error.cshtml @@ -1,4 +1,5 @@ -@model ErrorViewModel +@page +@model ErrorModel @{ ViewData["Title"] = "Error"; } @@ -15,7 +16,7 @@

Development Mode

- Swapping to Development environment will display more detailed information about the error that occurred. + Swapping to the Development environment displays detailed information about the error that occurred.

The Development environment shouldn't be enabled for deployed applications. diff --git a/samples/aspnetapp/aspnetapp/Pages/Error.cshtml.cs b/samples/aspnetapp/aspnetapp/Pages/Error.cshtml.cs new file mode 100644 index 0000000000..ff368111dd --- /dev/null +++ b/samples/aspnetapp/aspnetapp/Pages/Error.cshtml.cs @@ -0,0 +1,27 @@ +using System.Diagnostics; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; + +namespace aspnetapp.Pages; + +[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] +[IgnoreAntiforgeryToken] +public class ErrorModel : PageModel +{ + public string? RequestId { get; set; } + + public bool ShowRequestId => !string.IsNullOrEmpty(RequestId); + + private readonly ILogger _logger; + + public ErrorModel(ILogger logger) + { + _logger = logger; + } + + public void OnGet() + { + RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier; + } +} + diff --git a/samples/aspnetapp/aspnetapp/Views/Home/Index.cshtml b/samples/aspnetapp/aspnetapp/Pages/Index.cshtml similarity index 97% rename from samples/aspnetapp/aspnetapp/Views/Home/Index.cshtml rename to samples/aspnetapp/aspnetapp/Pages/Index.cshtml index c6144bd72a..3286abe629 100644 --- a/samples/aspnetapp/aspnetapp/Views/Home/Index.cshtml +++ b/samples/aspnetapp/aspnetapp/Pages/Index.cshtml @@ -1,4 +1,6 @@ -@using System.Runtime.InteropServices +@page +@model IndexModel +@using System.Runtime.InteropServices @using System.IO @using System.Diagnostics @{ diff --git a/samples/aspnetapp/aspnetapp/Pages/Index.cshtml.cs b/samples/aspnetapp/aspnetapp/Pages/Index.cshtml.cs new file mode 100644 index 0000000000..28b627f6b6 --- /dev/null +++ b/samples/aspnetapp/aspnetapp/Pages/Index.cshtml.cs @@ -0,0 +1,19 @@ +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; + +namespace aspnetapp.Pages; + +public class IndexModel : PageModel +{ + private readonly ILogger _logger; + + public IndexModel(ILogger logger) + { + _logger = logger; + } + + public void OnGet() + { + + } +} diff --git a/samples/aspnetapp/aspnetapp/Views/Home/Privacy.cshtml b/samples/aspnetapp/aspnetapp/Pages/Privacy.cshtml similarity index 80% rename from samples/aspnetapp/aspnetapp/Views/Home/Privacy.cshtml rename to samples/aspnetapp/aspnetapp/Pages/Privacy.cshtml index af4fb195a3..46ba96612e 100644 --- a/samples/aspnetapp/aspnetapp/Views/Home/Privacy.cshtml +++ b/samples/aspnetapp/aspnetapp/Pages/Privacy.cshtml @@ -1,4 +1,6 @@ -@{ +@page +@model PrivacyModel +@{ ViewData["Title"] = "Privacy Policy"; }

@ViewData["Title"]

diff --git a/samples/aspnetapp/aspnetapp/Pages/Privacy.cshtml.cs b/samples/aspnetapp/aspnetapp/Pages/Privacy.cshtml.cs new file mode 100644 index 0000000000..a2e7989f80 --- /dev/null +++ b/samples/aspnetapp/aspnetapp/Pages/Privacy.cshtml.cs @@ -0,0 +1,19 @@ +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; + +namespace aspnetapp.Pages; + +public class PrivacyModel : PageModel +{ + private readonly ILogger _logger; + + public PrivacyModel(ILogger logger) + { + _logger = logger; + } + + public void OnGet() + { + } +} + diff --git a/samples/aspnetapp/aspnetapp/Views/Shared/_Layout.cshtml b/samples/aspnetapp/aspnetapp/Pages/Shared/_Layout.cshtml similarity index 83% rename from samples/aspnetapp/aspnetapp/Views/Shared/_Layout.cshtml rename to samples/aspnetapp/aspnetapp/Pages/Shared/_Layout.cshtml index 3d323bfa98..c0ae8b2602 100644 --- a/samples/aspnetapp/aspnetapp/Views/Shared/_Layout.cshtml +++ b/samples/aspnetapp/aspnetapp/Pages/Shared/_Layout.cshtml @@ -11,8 +11,8 @@