简体   繁体   English

无法在 powershell 核心 6.2.0 中安装 nuget 包提供程序

[英]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:我尝试使用以下代码将 Az 模块安装到 powershell core 6.2.0:

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.但是在 azure webjob 控制台日志中,我收到关于安装 nuget 包提供程序的错误。 Then I try to install NuGet package provider using the followeing command:然后我尝试使用以下命令安装 NuGet 包提供程序:

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. [04/10/2019 15:54:00 > 674fe9: ERR] 未处理的异常:System.AggregateException:发生一个或多个错误。 (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 (未处理的异常 - 消息:'Microsoft.PackageManagement.Internal.Utility.Plugin.DynamicType' 的类型初始值设定项引发异常。' 名称:'TypeInitializationException' 堆栈跟踪:' 在 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.Plugin. .CreateProxy(Type tInterface, Object[] 实例) [04/10/2019 15:54:00 > 674fe9: ERR ] 在 Microsoft.PackageManagement.Internal.Utility.Plugin.DynamicInterface.DynamicCast(Type tInterface, Object[] 实例) [04/10/2019 15:54:00 > 674fe9: ERR ] 在 Microsoft.PackageManagement.Internal.Utility.Plugin.DynamicInterface.DynamicCast[TInterface](Object[] 实例) [04/10/2019 15:54:00 > 674fe9: ERR ] 在 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 tance) [04/10/2019 15:54:00 > 674fe9: ERR ] 在 Microsoft.PowerShell.PackageManagement.Cmdlets.CmdletBase.get_PackageManagementHost() [04/10/2019 15:54:00 > 674fe9] 在微软:ERR .PowerShell.PackageManagement.Cmdlets.CmdletBase.SelectProviders(String[] names) [04/10/2019 15:54:00 > 674fe9: ERR ] 在 Microsoft.PowerShell.PackageManagement.Cmdlets.CmdletWithProvider.get_SelectedProviders() [04/10 /2019 15:54:00 > 674fe9: ERR ] 在 Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackageProvider.get_SelectedProviders() [04/10/2019 15:54:00 > 674fe9: ERR ] 在 Microsoft.PowerShell.PackageCmdlets.Cmdlets.InstallPackageProvider.get_SelectedProviders() .CmdletWithProvider.b__23_0() [04/10/2019 15:54:00 > 674fe9: ERR ] 在 Microsoft.PackageManagement.Internal.Utility.Extensions.DictionaryExtensions.GetOrAdd[TKey,TValue](IDictionary 2 dictionary, TKey key, Func Funcictionary 2 dictionary, TKey key, Func 1 valueFunction) [04/10/2019 15:54:00 > 674fe9: ERR ] 在 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.' 74fe9: ERR ] 在 Microsoft.PowerShell.PackageManagement.Cmdlets.CmdletWithProvider.GenerateDynamicParameters() [04/10/2019 15:54:00 > 674fe9: ERR ] 在 Microsoft.PowerShell.PackageManagement.Cmdlets.AsyncCmdlet_Display_Class80> ()') ---> System.Exception: Unhandled Exception - Message:''Microsoft.PackageManagement.Internal.Utility.Plugin.DynamicType' 的类型初始值设定项引发异常。 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名称:'TypeInitializationException' 堆栈跟踪:' 在 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 ] 在 Microsoft.PackageManagement.Internal.Utility.Plugin.DynamicInterface.CreateProxy(Type tInterface, Object[] 实例) [04/10/2019 15:54:00 > 674fe9: ERR] 在 Microsoft .PackageManagement.Internal.Utility.Plugin.DynamicInterface.DynamicCast(Type tInterface, Object[] 实例) [04/10/2019 15:54:00 > 674fe9: ERR ] 在 Microsoft.PackageManagement.Internal.Utility.Plugin.DynamicInterface。 DynamicCast[TInterface](Object[] 实例) [04/10/2019 15:54:00 > 674fe9: ERR ] 在 Microsoft.PackageManagement.Internal.Utility.Plugin.DynamicInterfaceExtensions.As[TInterface](Object instance) [04/ 10/2019 15:54:00 > 674fe9: ERR ] 在 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 15:54:00 > 674fe9: ERR ] 在 Microsoft.PowerShell.PackageManagement.Cmdlets.CmdletBase.SelectProviders(String[] names) [04/10/2019 15:54:00 > 674fe9: ERR ] 在 Microsoft.PowerShell.PackageManagement .Cmdlets.CmdletWithProvider.get_SelectedProviders() [04/10/2019 15:54:00 > 674fe9: ERR ] 在 Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackageProvider.get_SelectedProviders() [04/10/2019:105 674fe9: ERR ] 在 Microsoft.PowerShell.PackageManagement.Cmdlets.CmdletWithProvider.b__23_0() [04/10/2019 15:54:00 > 674fe9: ERR ] 在 Microsoft.PackageManagement.Internal.Utility.Extensions.KeyExtensions.DictionaryExtensions.DictionaryExtensions ,TValue](IDictionary 2 dictionary, TKey key, Func 1 valueFunction) [04/10/2019 15:54:00 > 674fe9: ERR ] 在 Microsoft.PowerShell.PackageManagement.Cmdlets.CmdletWithProvider.get_CachedSelectedProviders() [04/10 2019 年 15:54:00 > 674fe9: ERR ] 在 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()' ] 在 Microsoft.PowerShell.PackageManagement.Cmdlets.AsyncCmdlet.<>c__DisplayClass83_0.b__0()'

What is wrong with it?它有什么问题? How to install package provider to powershell core?如何将软件包提供程序安装到 powershell 核心? Or how to install Az module without nuget?或者如何在没有 nuget 的情况下安装 Az 模块? 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 使用 Powershell 6 安装包提供程序

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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