Docker .NET 4.7.2 映像 - 无法安装 NuGet Package Provider

问题描述 投票:0回答:1

自 2024 年 3 月开始(1-2 周前)以来,当我拉取最新的 .NET 4.7.2 映像时,dockerfile 中的以下命令停止工作:

FROM mcr.microsoft.com/dotnet/framework/runtime:4.7.2

# install SQL-Server module
RUN powershell -Command \
    [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; \
    Install-PackageProvider -Name NuGet -Force; \
    Install-Module -Name SqlServer -Force -AllowClobber;

运行此程序时出现以下异常: Install-PackageProvider:找不到指定搜索条件的匹配项 对于提供商“NuGet”。包提供者需要“PackageManagement” 和“提供商”标签。请检查指定包裹是否有标签。

我尝试了以下解决方案来解决该问题:

  • 使用二进制或将 TLS 设置为 1.2
  • 设置执行策略为绕过
  • 在 32 位和 64 位 .NET 框架上设置强加密技术
  • 尝试使用 PowerShellGet 安装 nuget
  • 尝试直接注册 Package-Source - 使用 url
  • 尝试拉取具有不同标签的图像
  • 在安装 nuget 之前拆分命令,重新启动 powershell
  • 下载了 nuget.exe,遇到了证书问题,实现了一个单行类来绕过证书验证检查,将 nuget 关键字映射到 exe -> Install-Module 没有使用别名

不用说这一切都不起作用——上述作用的多种组合也起作用。 为了进行分析,这就是我的 dockerfile 现在的样子:

FROM mcr.microsoft.com/dotnet/framework/runtime:4.7.2-20240213-windowsservercore-ltsc2019

# install SQL-Server module
RUN powershell -Command \
    Set-ExecutionPolicy Bypass -Scope Process -Force; \
    [System.Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; \
    [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; \
    [Net.ServicePointManager]::SecurityProtocol; \
    # Set strong cryptography on 64 bit .Net Framework (version 4 and above)
    Set-ItemProperty -Path 'HKLM:\SOFTWARE\Wow6432Node\Microsoft\.NetFramework\v4.0.30319' -Name 'SchUseStrongCrypto' -Value '1' -Type DWord; \
    # Set strong cryptography on 32 bit .Net Framework (version 4 and above)
    Set-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\.NetFramework\v4.0.30319' -Name 'SchUseStrongCrypto' -Value '1' -Type DWord;
    #[Net.ServicePointManager]::SecurityProtocol;
    #Get-Module PowerShellGet, PackageManagement -ListAvailable; \
    #$PSVersionTable.PSVersion; \

RUN powershell -Command exit;

RUN powershell -Command \
    class TrustAllCertsPolicy : System.Net.ICertificatePolicy { [bool] CheckValidationResult([System.Net.ServicePoint] $a, [System.Security.Cryptography.X509Certificates.X509Certificate] $b, [System.Net.WebRequest] $c, [int] $d) { return $true }}; \
    [System.Net.ServicePointManager]::CertificatePolicy = [TrustAllCertsPolicy]::new(); \
    Invoke-WebRequest "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe" -OutFile "C:\nuget.exe"; \
    Set-Alias nuget "C:\nuget.exe" -Scope Global -Verbose; \
    #Install-Module PowerShellGet -Force -AllowClobber; \
    #Install-PackageProvider -Name NuGet -Force; \
    #Install-PackageProvider -Name 'NuGet' -Source 'PSGallery' -Scope 'CurrentUser' -Verbose -Force; \
    #Register-PackageSource -Name "NuGet" -Location "https://api.nuget.org/v3/index.json" -ProviderName NuGet -Force; \
    Install-Module -Name SqlServer -Force -AllowClobber -Verbose;

有谁知道问题是什么,或者我错过了什么,或者我下一步可以尝试什么? 欢迎任何建议。

PS.:图中的powershell版本是5.1

.net docker powershell image nuget
1个回答
0
投票

针对可能遇到相同问题的每个人的更新: 我找不到它不起作用的原因,但我发现这是一个操作系统问题。因此,我创建了一个新的 Windows Server 2019 VM,安装了 docker,它可以使用最初使用的代码:

FROM mcr.microsoft.com/dotnet/framework/runtime:4.7.2

# install SQL-Server module
RUN powershell -Command \
    [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; \
    Install-PackageProvider -Name NuGet -Force; \
    Install-Module -Name SqlServer -Force -AllowClobber;

如果有人找到它可以停止工作或停止工作的原因,请在下面发布答案 - 我有兴趣了解这个问题。

© www.soinside.com 2019 - 2024. All rights reserved.