我有一个使用Microsoft.NET.Sdk.WindowsDesktop
项目SDK的.NET Core 3.1控制台应用程序,因为它引用了Geometry3D
中的System.Windows.Media.Media3D
。
我想在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
答案 0 :(得分:0)
我知道了。我创建了一个在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