RamblingCookieMonster / PSDepend

PowerShell Dependency Handler
MIT License
285 stars 76 forks source link

Add support for -AllowClobber switch on PSGalleryModule #53

Closed devblackops closed 6 years ago

devblackops commented 6 years ago

I require BuildHelpers in many (most) of my modules and that module exposes the function Export-Metadata. I also have Joel's Configuration module installed which also exposes this function. This causes frequent issues when installing/updating BuildHelpers. To work around this the -AllowClobber is needed when installing the module. It would be nice if PSDepend allowed this switch to be passed to Install-Module.

PS>.\build.ps1 test
PackageManagement\Install-Package : The following commands are already available on this system:'Export-Metadata'. This module 'BuildHelpers' may override the existing commands. If you still want to install this module 'BuildHelpers',
use -AllowClobber parameter.
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.5.0.0\PSModule.psm1:1877 char:21
+ ...          $null = PackageManagement\Install-Package @PSBoundParameters
+                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (Microsoft.Power....InstallPackage:InstallPackage) [Install-Package], Exception
    + FullyQualifiedErrorId : CommandAlreadyAvailable,Validate-ModuleCommandAlreadyAvailable,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackage
megamorf commented 6 years ago

I'm also facing this issue which forces me to reinvent the wheel :(

RamblingCookieMonster commented 6 years ago

Sooo... Can you think of any reason to parameterize this, or should we just force AllowClobber when Install-Module is called?

IMHO it's not a very helpful parameter, particularly in this scenario. Might be easier to just hard code it? Or if we really need to parameterize it, default to using it?

Also: Has AllowClobber always been a parameter, or do we need to inspect the command bits to avoid using it on versions before it was added?

megamorf commented 6 years ago

I just checked and it's available in 1.0.0.1 that seems be shipped with Win10 and it's included with all versions in the PSGallery (first uploaded version: 1.1.0.0).

After pondering over it a bit I believe having an AllowClobber parameter that can be disabled for certain edge cases is a good idea.

RamblingCookieMonster commented 6 years ago

Sweet! Will add it in as a parameter, default to present; have most of it in place

RamblingCookieMonster commented 6 years ago

@devblackops - added this as the default, ping if it's still causing trouble!