SharpeRAD / Cake.Powershell

Powershell addin for Cake
http://cakebuild.net
MIT License
83 stars 36 forks source link

Running into Package Problems #87

Open mandalorianbob opened 3 years ago

mandalorianbob commented 3 years ago

Hi, I'm trying to use Cake.Powershell with a Powershell module that I download and install via Install-Module from the PSGallery.

I can run these commands in an admin Powershell window, but when I try to run it through the Cake.Powershell module it throws an exception. The commands are:

Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force
Find-Module UnitySetup

The actual calling code is

return context.StartPowershellScript(@"
                Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force
                Find-Module UnitySetup",
                new PowershellSettings()
                {
                    Modules = new List<string>() { "PowershellGet"},
                    BypassExecutionPolicy = true,
                    OutputToAppConsole = true
                }).Count > 1;

(I'm just trying to detect if it succesfully finds UnitySetup - installing the package provider probably throws off what gets returned, so I'll probably have to adjust my logic once I get it to stop throwing exceptions) And the exception I get is:

Unhandled Exception - Message:'The type initializer for 'Microsoft.PackageManagement.Internal.Utility.Plugin.DynamicType' threw an exception.' Name:'TypeInitializationException' Stack Trace:' at Microsoft.PackageManagement.Internal.Utility.Plugin.DynamicType.Create(Type tInterface, OrderedDictionary2 instanceMethods, List2 delegateMethods, List1 stubMethods, List2 usedInstances)

Now I see you have Powershell Core enabled only for Linux. I'd just like to ask that if practicable, that there be an option for Windows users to use Powershell Core instead of Powershell. I'm like, 90% sure that this problem would vanish in Powershell Core.

However, do you have any thoughts on what I can do to try to mitigate this issue?

mandalorianbob commented 3 years ago

Okay, so after a bunch of reading, I'm better understanding that the Powershell.SDK allows for re-hosting Powershell, and that for .NET 5.0 it's using Powershell 7.1.2. I switched over to .NET 5 just to make sure the issue wasn't from an older version of Powershell.

I'm still running into the problem, but I'm starting to suspect this is more about installing modules into the PS Host than anything related to Powershell version.