【问题标题】:Docker Image for Windows server 2016 with framework .NET 5.0带有框架 .NET 5.0 的 Windows 服务器 2016 的 Docker 映像
【发布时间】:2021-10-20 16:15:39
【问题描述】:

我们在 Windows Server 2016 上安装了 Docker。我们拥有的应用程序位于 .NET 5.0 中,使用 VS 2019 IDE。我无法使用以下代码启动并运行 Docker 容器。 VS 2019 构建工具安装失败。非常感谢任何帮助。

我尝试过的事情:

  1. 安装 .NET 5.0 (sdk/runtime) 似乎是成功的,但 dotnetfx(退出代码 3010)需要重新启动,这是根本原因。由于此等待重启,VS 2019 构建工具的安装失败。
  2. 我尝试使用其他图像,但出现与守护进程相关的错误。看起来我找不到为 Windows Server 2016 主机安装了 .NET 5.0 的 Docker 映像

DockerFile:

# escape=`
FROM mcr.microsoft.com/windows/servercore:1607
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]


# Install Chocolatey
RUN write-host "*********** Chocolatey Install"
RUN Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))


# Install Nuget
RUN write-host "*********** NuGet Install"
RUN choco install nuget.commandline --version=5.11.0


# Install .net 5.0 framework
# RUN write-host "*********** Install .Net 5.0"
RUN choco install dotnet-5.0-sdk --version=5.0.402 --yes


# Download and Install Build Tools
RUN write-host "*********** Download and Install Build Tools 2019"
RUN choco install visualstudio2019buildtools --version=16.11.5.0 --yes

错误:

已安装:

  • dotnetfx v4.8.0.20190930
  • chocolatey-visualstudio.extension v1.10.0
  • visualstudio-installer v2.0.2
  • chocolatey-dotnetfx.extension v1.0.1

需要重启的包:

  • dotnetfx(退出代码 3010)

最近的软件包更改表明需要重新启动。请 尽早重启。

失败

  • visualstudio2019buildtools(退出 -1) - 运行“C:\ProgramData\chocolatey\lib\visualstudio2019buildtools\tools\ChocolateyInstall.ps1”时出错。

【问题讨论】:

    标签: docker dockerfile .net-5 docker-image build-tools


    【解决方案1】:

    我不知道 choco 如何处理 VS Build Tools 的安装,所以我不能确定如何避免重启要求。

    但是,您应该能够避免创建自己的图像,而是使用现有的mcr.microsoft.com/dotnet/framework/sdk:4.8-windowsservercore-ltsc2016 图像。这实际上提供了您需要的一切:

    【讨论】:

    • 感谢@MattThalman 我使用了该图像,但在尝试构建/发布时出现以下错误... C:\Program Files\dotnet\sdk\2.2.402\Microsoft.Common .CurrentVersion.targets(1175,5):错误 MSB3644:未找到 .NETFramework,Version=v5.0 的参考程序集。要解决此问题,请为此框架版本安装开发包(SDK/Targeting Pack)或重新定位您的应用程序。您可以在aka.ms/msbuild/developerpacks 下载 .NET Framework 开发人员包
    • 该容器映像中没有 C:\Program Files\dotnet\sdk\2.2.402\Microsoft.Common.CurrentVersion.targets 文件。所以这很奇怪。你在安装其他东西吗?在这种情况下,您的 Dockerfile 是什么样的?或者您没有在该标签的最新图像上运行?
    • 所以主机安装了.net core 2.2。可能这就是它选择 2.2 sdk 的原因。我运行了 dotnet --info 和 dotnet --version 并返回了 2.2 版本。我想可能是在安装 .net 5.0 之后它应该选择最新/最好的 sdk
    • 安装 .NET 5 会导致它默认使用它,但可能会被 global.json 文件覆盖。但是为什么您的主机与 Dockerfile 中发生的事情相关?
    • Docker 文件:`#escape=` FROM mcr.microsoft.com/dotnet/framework/sdk:4.8-windowsservercore-ltsc2016 SHELL ["powershell", "-Command", "$ErrorActionPreference = ' Stop'; $ProgressPreference = 'SilentlyContinue';"] RUN Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('chocolatey.org/install.ps1')) RUN choco install nodejs --version=10.15.0 -y RUN npm install webpack@4.1.1 -g RUN npm install webpack-cli @3.2.1 -g `
    猜你喜欢
    • 2020-08-28
    • 1970-01-01
    • 1970-01-01
    • 2017-07-27
    • 2019-03-25
    • 2016-10-24
    • 1970-01-01
    • 2021-09-29
    • 2017-03-06
    相关资源
    最近更新 更多