Docker .NET 4.7.2 Image - Cant install NuGet Package Provider

38 Views Asked by At

Since around the beginning of march 2024 (1-2 weeks ago), when I pull the latest .NET 4.7.2 image the following commands in my dockerfile stopped working:

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;

Running this I got the following exception: Install-PackageProvider : No match was found for the specified search criteria for the provider 'NuGet'. The package provider requires 'PackageManagement' and 'Provider' tags. Please check if the specified package has the tags.

I tried following solutions to fix the issue:

  • Set the TLS to 1.2 using binary or
  • Set the execution policy to bypass
  • Set strong cryptography on 32 and 64 bit .NET framework
  • Tried to install nuget using PowerShellGet
  • Tried to register Package-Source directly - using the url
  • Tried to pull the image with different tags
  • Split the commands, to restart powershell - before installing nuget
  • Downloaded nuget.exe, ran into cert problems, implemented an one line class to bypass the cert validation checks, mapped the nuget keyword to the exe -> Install-Module didnt use the alias

Needless to say this all didnt work - also numerous combinations of the above dint work as well. For analysis, this is how my dockerfile looks now:

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;

Does anyone have an idea, what the problem is, or what am I missing, or what i could try next? Any advice is welcome.

PS.: powershell version in the image is 5.1

0

There are 0 best solutions below