Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running into Package Problems #87

Open
mandalorianbob opened this issue Jul 1, 2021 · 1 comment
Open

Running into Package Problems #87

mandalorianbob opened this issue Jul 1, 2021 · 1 comment

Comments

@mandalorianbob
Copy link

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
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant