Search code examples
c#azuredocker.net-framework-version.net-4.8

Deploy .NET framework 4.8 console app to Azure Docker instance


I was able to run the app on Docker Desktop. I am able to deploy it to azure container registry. However it fails creating container instance.

I am a bit at a loss to figure out how to properly change my dockerfile to use one of the listed supported versions.

I was able to run a test docker instance in .NET 7 (It was a lot friendlier to setup). However, I have a primary third party dependency that targets .NET framework 4.8.

Error:

Error screenshot {"code":"DeploymentFailed","target":"/subscriptions/.../deployments/Microsoft.ContainerInstances-20231003202653","message":"At least one resource deployment operation failed. Please list deployment operations for details. Please see https://aka.ms/arm-deployment-operations for usage details.","details":[{"code":"UnsupportedWindowsVersion","message":"Unsupported windows image version. Supported versions are 'Windows Server 2019 - Before 2B, Windows Server 2019 - After 2B, Windows Server, Version 1903 - After 2B, Windows Server, Version 2004, Windows Server 2022, Windows Server LTSC Preview Build'"}]}

Dockerfile:

FROM mcr.microsoft.com/dotnet/framework/sdk:4.8 AS build
WORKDIR /app

COPY \*.csproj .
RUN dotnet restore

COPY . .
WORKDIR /app
RUN dotnet publish -c Release -o out --no-restore

FROM mcr.microsoft.com/dotnet/framework/runtime:4.8 AS runtime
WORKDIR /app
COPY --from=build /app/out ./
ENTRYPOINT \["MyApp.exe"\]

SDK style project:

<Project Sdk="Microsoft.NET.Sdk;Microsoft.NET.Sdk.Publish">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
     <TargetFramework>net48</TargetFramework>
    <DockerDefaultTargetOS>Windows</DockerDefaultTargetOS>
    <DockerfileContext>.</DockerfileContext>
    <ApplicationManifest>app.manifest</ApplicationManifest>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.5" />>
  </ItemGroup>
</Project>

The app.manifest elevates the app to be able to read/write registry.

<?xml version="1.0" encoding="utf-8"?>
<asmv1:assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <assemblyIdentity version="1.0.0.0" name="WorkShark48.exe" />
   <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
      <security>
         <requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
            <requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
         </requestedPrivileges>
      </security>
   </trustInfo>
</asmv1:assembly>

Solution

  • https://hub.docker.com/_/microsoft-dotnet-framework-sdk/

    It looks like docker file is using OS Version: windowsservercore-ltsc2022

    which could be causing the error you are seeing.

    Try changing the tag to: 4.8-windowsservercore-ltsc2019 OR 4.8-windowsservercore-ltsc2016 instead of 4.8 to see if that will resolve the error.