From 31686228e932ce718f59d95b9b767fae0f85a8cc Mon Sep 17 00:00:00 2001 From: Paul Broadwith Date: Mon, 30 Aug 2021 16:43:50 +0100 Subject: [PATCH] (#2333) Disable loading of DLL under extensions path As there isn't a way to determine whether a DLL is a usable PowerShell module without loading it into memory, we're better off not loading DLLs directly, as it has caused issues several times in the past (see: #2078, #1041). This has previously required us to create an ever-expanding list of exceptions to the loading behaviour. Instead, if folks want to load DLLs as powershell modules, they can package them alongside a PSM1 file that handles the DLL import itself. This removes the need for Chocolatey to guess which dlls are powershell modules and which should not be loaded. --- .../helpers/chocolateyInstaller.psm1 | 30 ------------------- 1 file changed, 30 deletions(-) diff --git a/src/chocolatey.resources/helpers/chocolateyInstaller.psm1 b/src/chocolatey.resources/helpers/chocolateyInstaller.psm1 index 271e628359..1d5263c9d5 100644 --- a/src/chocolatey.resources/helpers/chocolateyInstaller.psm1 +++ b/src/chocolatey.resources/helpers/chocolateyInstaller.psm1 @@ -56,36 +56,6 @@ $currentAssemblies = [System.AppDomain]::CurrentDomain.GetAssemblies() $extensionsPath = Join-Path "$helpersPath" '..\extensions' if (Test-Path($extensionsPath)) { Write-Debug 'Loading community extensions' - Get-ChildItem $extensionsPath -recurse -filter "*.dll" | Select -ExpandProperty FullName | % { - $path = $_; - if ($path.Contains("extensions\chocolatey\lib-synced")) { continue } - - try { - Write-Debug "Importing '$path'"; - $fileNameWithoutExtension = $([System.IO.Path]::GetFileNameWithoutExtension($path)) - Write-Debug "Loading '$fileNameWithoutExtension' extension."; - $loaded = $false - $currentAssemblies | % { - $name = $_.GetName().Name - if ($name -eq $fileNameWithoutExtension) { - Import-Module $_ - $loaded = $true - } - } - - if (!$loaded) { - if ($fileNameWithoutExtension -ne "chocolateygui.licensed") { - Import-Module $path; - } - } - } catch { - if ($env:ChocolateyPowerShellHost -eq 'true') { - Write-Warning "Import failed for '$path'. Error: '$_'" - } else { - Write-Warning "Import failed for '$path'. If it depends on a newer version of the .NET framework, please make sure you are using the built-in PowerShell Host. Error: '$_'" - } - } - } #Resolve-Path $extensionsPath\**\*\*.psm1 | % { Write-Debug "Importing `'$_`'"; Import-Module $_.ProviderPath } Get-ChildItem $extensionsPath -recurse -filter "*.psm1" | Select -ExpandProperty FullName | % { Write-Debug "Importing `'$_`'"; Import-Module $_; } }