【问题标题】:Install .NET Runtime on .NET Core 3.1 Nano Server Docker Image在 .NET Core 3.1 Nano Server Docker 映像上安装 .NET 运行时
【发布时间】:2020-07-03 13:33:30
【问题描述】:

我有一个使用 Microsoft.NET.Sdk.WindowsDesktop 项目 SDK 的 .NET Core 3.1 控制台应用程序,因为它在 System.Windows.Media.Media3D 中引用了 Geometry3D

我想在 Windows Nano Server 上的 Docker 容器中运行它,但在执行 docker run 时收到以下错误:

It was not possible to find any compatible framework version
The framework 'Microsoft.WindowsDesktop.App', version '3.1.0' was not found.
  - No frameworks were found.

You can resolve the problem by installing the specified framework and/or SDK.

The specified framework can be found at:
  - https://aka.ms/dotnet-core-applaunch?framework=Microsoft.WindowsDesktop.App&framework_version=3.1.0&arch=x64&rid=win10-x64

如何安装所需的 sdk 和运行时?

这是我现有的 Dockerfile:

FROM mcr.microsoft.com/dotnet/core/runtime:3.1-nanoserver-1903 AS base
WORKDIR /app

FROM mcr.microsoft.com/dotnet/core/sdk:3.1-nanoserver-1903 AS build
WORKDIR /src
COPY ["HelloWpfCore/HelloWpfCore.csproj", "HelloWpfCore/"]
RUN dotnet restore "HelloWpfCore/HelloWpfCore.csproj"
COPY . .
WORKDIR "/src/HelloWpfCore"
RUN dotnet build "HelloWpfCore.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "HelloWpfCore.csproj" -c Release -o /app/publish

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "HelloWpfCore.dll"]

GitHub 仓库在这里:https://github.com/tonysneed/hello-netcore-wpf-nano

【问题讨论】:

    标签: .net-core docker-run nano-server


    【解决方案1】:

    我想通了。我创建了一个在 Nano Server 基础映像上安装 Windows 桌面运行时的映像。

    # escape=`
    
    # Installer image
    FROM mcr.microsoft.com/windows/servercore:1909 AS installer
    
    SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
    
    # Retrieve .NET Core Runtime
    # USER ContainerAdministrator
    RUN $dotnet_version = '3.1.5'; `
        Invoke-WebRequest -OutFile dotnet-installer.exe https://download.visualstudio.microsoft.com/download/pr/86835fe4-93b5-4f4e-a7ad-c0b0532e407b/f4f2b1239f1203a05b9952028d54fc13/windowsdesktop-runtime-3.1.5-win-x64.exe; `
        $dotnet_sha512 = '5df17bd9fed94727ec5b151e1684bf9cdc6bfd3075f615ab546759ffca0679d23a35fcf7a8961ac014dd5a4ff0d22ef5f7434a072e23122d5c0415fcd4198831'; `
        if ((Get-FileHash dotnet-installer.exe -Algorithm sha512).Hash -ne $dotnet_sha512) { `
            Write-Host 'CHECKSUM VERIFICATION FAILED!'; `
            exit 1; `
        }; `
        `
        ./dotnet-installer.exe /S
    
    # Runtime image 
    FROM mcr.microsoft.com/windows/nanoserver:1909
    
    ENV `
        # Enable detection of running in a container
        DOTNET_RUNNING_IN_CONTAINER=true
    
    # In order to set system PATH, ContainerAdministrator must be used
    USER ContainerAdministrator
    RUN setx /M PATH "%PATH%;C:\Program Files\dotnet"
    USER ContainerUser
    
    COPY --from=installer ["/Program Files/dotnet", "/Program Files/dotnet"]
    

    我将此推送到我在 Docker Hub 上的仓库:https://hub.docker.com/repository/docker/tonysneed/dotnet-runtime-windowsdesktop

    然后我简单地使用这个自定义图像作为我的示例应用程序的基础图像:https://github.com/tonysneed/hello-netcore-wpf-nano

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多