简体   繁体   中英

Can't install nuget package provider in powershell core 6.2.0

I have webjob in azure. I try to install Az module to powershell core 6.2.0 using the following code:

using (PowerShell ps = PowerShell.Create())
{
    ps.Runspace = runspace;
    ps.AddScript("Install-Module -Name Az -AllowClobber -Scope CurrentUser - 
    Force;");
}

But in azure webjob console log I get an error about installing nuget package provider. Then I try to install NuGet package provider using the followeing command:

ps.AddScript("Install-PackageProvider -Name NuGet -MinimumVersion '2.8.5.201' -Force;");

But I get the following error:

[04/10/2019 15:54:00 > 674fe9: ERR ] Unhandled Exception: System.AggregateException: One or more errors occurred. (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, OrderedDictionary 2 instanceMethods, List 2 delegateMethods, List 1 stubMethods, List 2 usedInstances) [04/10/2019 15:54:00 > 674fe9: ERR ] at Microsoft.PackageManagement.Internal.Utility.Plugin.DynamicInterface.CreateProxy(Type tInterface, Object[] instances) [04/10/2019 15:54:00 > 674fe9: ERR ] at Microsoft.PackageManagement.Internal.Utility.Plugin.DynamicInterface.DynamicCast(Type tInterface, Object[] instances) [04/10/2019 15:54:00 > 674fe9: ERR ] at Microsoft.PackageManagement.Internal.Utility.Plugin.DynamicInterface.DynamicCast[TInterface](Object[] instances) [04/10/2019 15:54:00 > 674fe9: ERR ] at Microsoft.PackageManagement.Internal.Utility.Plugin.DynamicInterfaceExtensions.As[TInterface](Object ins tance) [04/10/2019 15:54:00 > 674fe9: ERR ] at Microsoft.PowerShell.PackageManagement.Cmdlets.CmdletBase.get_PackageManagementHost() [04/10/2019 15:54:00 > 674fe9: ERR ] at Microsoft.PowerShell.PackageManagement.Cmdlets.CmdletBase.SelectProviders(String[] names) [04/10/2019 15:54:00 > 674fe9: ERR ] at Microsoft.PowerShell.PackageManagement.Cmdlets.CmdletWithProvider.get_SelectedProviders() [04/10/2019 15:54:00 > 674fe9: ERR ] at Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackageProvider.get_SelectedProviders() [04/10/2019 15:54:00 > 674fe9: ERR ] at Microsoft.PowerShell.PackageManagement.Cmdlets.CmdletWithProvider.b__23_0() [04/10/2019 15:54:00 > 674fe9: ERR ] at Microsoft.PackageManagement.Internal.Utility.Extensions.DictionaryExtensions.GetOrAdd[TKey,TValue](IDictionary 2 dictionary, TKey key, Func 1 valueFunction) [04/10/2019 15:54:00 > 674fe9: ERR ] at Microsoft.PowerShell.PackageManagement.Cmdlets.CmdletWithProvider.get_CachedSelectedProviders() [04/10/2019 15:54:00 > 6 74fe9: ERR ] at Microsoft.PowerShell.PackageManagement.Cmdlets.CmdletWithProvider.GenerateDynamicParameters() [04/10/2019 15:54:00 > 674fe9: ERR ] at Microsoft.PowerShell.PackageManagement.Cmdlets.AsyncCmdlet.<>c__DisplayClass83_0.b__0()') ---> System.Exception: 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, OrderedDictionary 2 instanceMethods, List 2 delegateMethods, List 1 stubMethods, List 2 usedInstances) [04/10/2019 15:54:00 > 674fe9: ERR ] at Microsoft.PackageManagement.Internal.Utility.Plugin.DynamicInterface.CreateProxy(Type tInterface, Object[] instances) [04/10/2019 15:54:00 > 674fe9: ERR ] at Microsoft.PackageManagement.Internal.Utility.Plugin.DynamicInterface.DynamicCast(Type tInterface, Object[] instances) [04/10/2019 15:54:00 > 674fe9: ERR ] at Microsoft.PackageManagement.Internal.Utility.Plugin.DynamicInterface.DynamicCast[TInterface](Object[] instances) [04/10/2019 15:54:00 > 674fe9: ERR ] at Microsoft.PackageManagement.Internal.Utility.Plugin.DynamicInterfaceExtensions.As[TInterface](Object instance) [04/10/2019 15:54:00 > 674fe9: ERR ] at Microsoft.PowerShell.PackageManagement.Cmdlets.CmdletBase.get_PackageManagementHost() [04/10/2019 15:54:00 > 674fe9: ERR ] at Microsoft.PowerShell.PackageManagement.Cmdlets.CmdletBase.SelectProviders(String[] names) [04/10/2019 15:54:00 > 674fe9: ERR ] at Microsoft.PowerShell.PackageManagement.Cmdlets.CmdletWithProvider.get_SelectedProviders() [04/10/2019 15:54:00 > 674fe9: ERR ] at Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackageProvider.get_SelectedProviders() [04/10/2019 15:54:00 > 674fe9: ERR ] at Microsoft.PowerShell.PackageManagement.Cmdlets.CmdletWithProvider.b__23_0() [04/10/2019 15:54:00 > 674fe9: ERR ] at Microsoft.PackageManagement.Internal.Utility.Extensions.DictionaryExtensions.GetOrAdd[TKey,TValue](IDictionary 2 dictionary, TKey key, Func 1 valueFunction) [04/10/2019 15:54:00 > 674fe9: ERR ] at Microsoft.PowerShell.PackageManagement.Cmdlets.CmdletWithProvider.get_CachedSelectedProviders() [04/10/2019 15:54:00 > 674fe9: ERR ] at Microsoft.PowerShell.PackageManagement.Cmdlets.CmdletWithProvider.GenerateDynamicParameters() [04/10/2019 15:54:00 > 674fe9: ERR ] at Microsoft.PowerShell.PackageManagement.Cmdlets.AsyncCmdlet.<>c__DisplayClass83_0.b__0()'

What is wrong with it? How to install package provider to powershell core? Or how to install Az module without nuget? Help, please)

This might also seem to work. Have you tried this option?

Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force

You can also take a look at the below article just for the reference.

Install Package Provider with Powershell 6

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM