无法在Powershell Core 6.2.0中安装nuget软件包提供程序

时间:2019-04-10 16:06:58

标签: azure powershell nuget

我有天蓝色的webjob。我尝试使用以下代码将Az模块安装到Powershell Core 6.2.0:

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

但是在azure webjob控制台日志中,我收到有关安装nuget软件包提供程序的错误。然后,我尝试使用以下命令安装NuGet软件包提供程序:

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

但是出现以下错误:

  

[04/10/2019 15:54:00> 674fe9:ERR]未处理的异常:System.AggregateException:发生一个或多个错误。 (未处理的异常-消息:'Microsoft.PackageManagement.Internal.Utility.Plugin.DynamicType的类型初始化程序引发了异常。'Name:'TypeInitializationException'Stack Trace:'at Microsoft.PackageManagement.Internal.Utility.Plugin.DynamicType .Create(类型tInterface,OrderedDictionary 2 instanceMethods, List 2个委托方法,列表1 stubMethods, List 2个使用实例)   [04/10/2019 15:54:00> 674fe9:错误]在Microsoft.PackageManagement.Internal.Utility.Plugin.DynamicInterface.CreateProxy(Type tInterface,Object [] instance)   [04/10/2019 15:54:00> 674fe9:ERR]在Microsoft.PackageManagement.Internal.Utility.Plugin.DynamicInterface.DynamicCast(类型tInterface,Object []实例)   [04/10/2019 15:54:00> 674fe9:错误]在Microsoft.PackageManagement.Internal.Utility.Plugin.DynamicInterface.DynamicCast [TInterface](Object []实例)   [04/10/2019 15:54:00> 674fe9:错误]在Microsoft.PackageManagement.Internal.Utility.Plugin.DynamicInterfaceExtensions.As [TInterface](对象实例)   [04/10/2019 15:54:00> 674fe9:错误]在Microsoft.PowerShell.PackageManagement.Cmdlets.CmdletBase.get_PackageManagementHost()   [04/10/2019 15:54:00> 674fe9:错误]在Microsoft.PowerShell.PackageManagement.Cmdlets.CmdletBase.SelectProviders(String [] names)   [04/10/2019 15:54:00> 674fe9:错误]在Microsoft.PowerShell.PackageManagement.Cmdlets.CmdletWithProvider.get_SelectedProviders()   [04/10/2019 15:54:00> 674fe9:错误]在Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackageProvider.get_SelectedProviders()   [04/10/2019 15:54:00> 674fe9:错误]在Microsoft.PowerShell.PackageManagement.Cmdlets.CmdletWithProvider.b__23_0()   [04/10/2019 15:54:00> 674fe9:错误]在Microsoft.PackageManagement.Internal.Utility.Extensions.DictionaryExtensions.GetOrAdd [TKey,TValue](IDictionary 2 dictionary, TKey key, Func 1 valueFunction)   [04/10/2019 15:54:00> 674fe9:错误]在Microsoft.PowerShell.PackageManagement.Cmdlets.CmdletWithProvider.get_CachedSelectedProviders()   [04/10/2019 15:54:00> 674fe9:错误]在Microsoft.PowerShell.PackageManagement.Cmdlets.CmdletWithProvider.GenerateDynamicParameters()   [04/10/2019 15:54:00> 674fe9:ERR]在Microsoft.PowerShell.PackageManagement.Cmdlets.AsyncCmdlet。<> c__DisplayClass83_0.b__0()')---> System.Exception:未处理的异常-消息:' 'Microsoft.PackageManagement.Internal.Utility.Plugin.DynamicType'的类型初始值设定项引发了异常。名称:“ TypeInitializationException”堆栈跟踪:“位于Microsoft.PackageManagement.Internal.Utility.Plugin.DynamicType.Create(类型tInterface,OrderedDictionary 2 instanceMethods, List 2个委托方法,列表1 stubMethods, List 2个usedInstances)   [04/10/2019 15:54:00> 674fe9:错误]在Microsoft.PackageManagement.Internal.Utility.Plugin.DynamicInterface.CreateProxy(Type tInterface,Object [] instance)   [04/10/2019 15:54:00> 674fe9:ERR]在Microsoft.PackageManagement.Internal.Utility.Plugin.DynamicInterface.DynamicCast(类型tInterface,Object []实例)   [04/10/2019 15:54:00> 674fe9:错误]在Microsoft.PackageManagement.Internal.Utility.Plugin.DynamicInterface.DynamicCast [TInterface](Object []实例)   [04/10/2019 15:54:00> 674fe9:错误]在Microsoft.PackageManagement.Internal.Utility.Plugin.DynamicInterfaceExtensions.As [TInterface](对象实例)   [04/10/2019 15:54:00> 674fe9:错误]在Microsoft.PowerShell.PackageManagement.Cmdlets.CmdletBase.get_PackageManagementHost()   [04/10/2019 15:54:00> 674fe9:错误]在Microsoft.PowerShell.PackageManagement.Cmdlets.CmdletBase.SelectProviders(String [] names)   [04/10/2019 15:54:00> 674fe9:错误]在Microsoft.PowerShell.PackageManagement.Cmdlets.CmdletWithProvider.get_SelectedProviders()   [04/10/2019 15:54:00> 674fe9:错误]在Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackageProvider.get_SelectedProviders()   [04/10/2019 15:54:00> 674fe9:错误]在Microsoft.PowerShell.PackageManagement.Cmdlets.CmdletWithProvider.b__23_0()   [04/10/2019 15:54:00> 674fe9:错误]在Microsoft.PackageManagement.Internal.Utility.Extensions.DictionaryExtensions.GetOrAdd [TKey,TValue](IDictionary 2 dictionary, TKey key, Func 1 valueFunction)   [04/10/2019 15:54:00> 674fe9:错误]在Microsoft.PowerShell.PackageManagement.Cmdlets.CmdletWithProvider.get_CachedSelectedProviders()   [04/10/2019 15:54:00> 674fe9:错误]在Microsoft.PowerShell.PackageManagement.Cmdlets.CmdletWithProvider.GenerateDynamicParameters()   [04/10/2019 15:54:00> 674fe9:错误]在Microsoft.PowerShell.PackageManagement.Cmdlets.AsyncCmdlet。<> c__DisplayClass83_0.b__0()'

这有什么问题?如何将软件包提供程序安装到Powershell核心? 或如何安装没有Nuget的Az模块? 请帮助)

1 个答案:

答案 0 :(得分:0)

这似乎也可行。 您尝试过此选项吗?

Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force

您也可以参考以下文章。

Install Package Provider with Powershell 6

希望这会有所帮助。