You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Dockerfile中更新ASP.NET Core版本(Azure DevOps场景)

Fix: Install ASP.NET Core 2.2.5 Runtime in Your Windows Docker Container

Got it, your issue is that the base aspnet:2.2-nanoserver-sac2016 image only ships with version 2.2.2 of Microsoft.AspNetCore.All, but your application requires 2.2.5. Since you're working with a Windows Nano Server container, we can add PowerShell commands to download and install the missing runtime version directly in your Dockerfile.

Here's the updated Dockerfile with the necessary steps:

FROM mcr.microsoft.com/dotnet/core/aspnet:2.2-nanoserver-sac2016 AS runtime
WORKDIR /app
COPY SampleMvcApp/out ./

# Download and install ASP.NET Core 2.2.5 Runtime Hosting Bundle
RUN powershell -Command \
    $ErrorActionPreference = 'Stop'; \
    # Replace this with the official 2.2.5 hosting bundle download URL you've found
    $installerUrl = '[YOUR_DOWNLOAD_URL]'; \
    Invoke-WebRequest -Uri $installerUrl -OutFile ./dotnet-hosting.exe; \
    # Run installer in silent mode (no user interaction, no auto-restart)
    Start-Process -FilePath ./dotnet-hosting.exe -ArgumentList '/quiet /norestart' -Wait; \
    # Clean up the installer to reduce image size
    Remove-Item -Path ./dotnet-hosting.exe -Force

ENTRYPOINT ["dotnet", "Meta-Analytics.dll"]

Key Details About This Approach:

  • Silent Installation: The /quiet /norestart flags ensure the installer runs without any prompts and doesn't attempt to restart the container (which isn't needed here). The -Wait parameter makes sure the build process pauses until installation is fully complete.
  • Error Handling: $ErrorActionPreference = 'Stop' ensures the build fails immediately if any step (like downloading the installer) goes wrong, so you don't end up with a broken image.
  • Image Size Optimization: We delete the installer after installation to keep the Docker image as small as possible—this is a standard best practice for containerized applications.

Quick Validation Tip:

If you want to confirm the runtime installed correctly during testing, you can add a temporary step right after the installation:

RUN dotnet --info

This will print out all installed .NET Core runtimes. Once you verify 2.2.5 is present, you can remove this line to keep your Dockerfile clean.

内容的提问来源于stack exchange,提问作者Rajesh

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.13 08:06:12