我对docker容器或azure webapp中的powershell核心有疑问。 我开发了一些webjob(.net核心应用程序),尝试使用Microsoft.PowerShell.Commands.Diagnostics,Microsoft.PowerShell.SDK,Microsoft.WSMan.Management软件包(版本6.2.0)执行powershell命令。 在我的本地环境中(我已经安装了powershell 6,默认情况下是powershell 5),webjob可以正常工作而没有任何问题。然后,我尝试将webjob部署在linux docker容器中。 dockerfile包含一些有关在容器中安装Powershell Core 6.2.0的说明。因此,带有我的webjob的docker容器(OS Debian 9)在安装的powershell内核下运行。然后我的代码尝试执行以下命令:
using (PowerShell ps = PowerShell.Create())
{
ps.AddScript("Get-PackageProvider -ListAvailable");
var results = ps.Invoke();
}
然后我得到以下错误:
未处理的异常:System.AggregateException:发生一个或多个错误。 (“ Get-PackageProvider”一词未被识别为cmdlet,函数,脚本文件或可操作程序的名称。 检查名称的拼写,或者是否包含路径,请验证路径是否正确,然后重试。)---> System.Management.Automation.CommandNotFoundException:术语“ Get-PackageProvider”未被识别为名称cmdlet,函数,脚本文件或可操作程序的名称。 检查名称的拼写,或者是否包含路径,请验证路径是否正确,然后重试。 在System.Management.Automation.CommandDiscovery.LookupCommandInfo处(字符串commandName,CommandTypes commandTypes,SearchResolutionOptions searchResolutionOptions,CommandOrigin commandOrigin,ExecutionContext上下文) 在System.Management.Automation.CommandDiscovery.LookupCommandInfo处(字符串commandName,CommandOrigin commandOrigin,ExecutionContext上下文) 在System.Management.Automation.CommandDiscovery.LookupCommandInfo(字符串commandName,CommandOrigin commandOrigin) System.Management.Automation.PipelineOps.AddCommand(System.Management.Automation.CommandDiscovery.LookupCommandProcessor(String commandName,CommandOrigin commandOrigin,Nullable1 useLocalScope)在System.Management.Automation.ExecutionContext.CreateCommand(String command,Boolean dotSource)在System.Management.Automation.PipelineOps.AddCommand ,位于System.Management.Automation.PipelineOps.InvokePipeline(对象输入,布尔值ignoreInput,CommandParameterInternal [] [] [] pipeElements,CommandBaseAst [] pipeElementAsts,CommandRedirection [] []中的CommandParameterInternal [] commandElements,CommandBaseAst commandBaseAst,CommandRedirection []重定向,ExecutionContext上下文) ] commandRedirections,FunctionContext funcContext),位于System.Management.Automation.Interpreter.ActionCallInstruction6.Run(InterpretedFrame框架) 在System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame框架) ---内部异常堆栈跟踪的结尾---
我遇到了同样的问题。当我运行webjob时,出现该错误。 我已经在Google上搜索了很多资源,并尝试了许多不同的解决方案,但是其中任何一个都没有帮助我。 请问你能帮帮我吗? 为什么这个问题不在本地环境中重现,而仅在天蓝色和容器中重现?
谢谢!