【发布时间】:2018-12-11 03:58:49
【问题描述】:
我正在尝试在 Azure Functions v2 中使用 .NET Core 编写函数应用程序。当使用来自 Nuget 的 Microsoft.Powershell.SDK 包(.NET Core PowerShell 运行时需要)时,我无法让 Visual Studio 将 System.Management.Automation 库与我的 Function App 一起复制到 bin。
这会导致以下错误:
System.Private.CoreLib: Exception while executing function: Function1. TestPowershellInFunction: Could not load file or assembly 'System.Management.Automation, Version=6.1.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified. System.Private.CoreLib: Could not load the specified file.
我在现有的 Azure 函数和新的解决方案中重现了这一点,只需创建一个 Timer 函数并添加以下 sn-p:
PowerShell shell = PowerShell.Create();
IEnumerable<PSObject> result = shell.AddScript("Write-Output 'Hello, World!'").Invoke();
foreach(PSObject line in result)
{
log.LogInformation(line.ToString());
}
这适用于安装了 PowerShell Nuget 的新控制台应用程序,但添加到函数应用程序时出现错误。我确实注意到 System.Management.Automation 没有使用常规控制台应用程序放入 bin 目录中,但我不确定如何解释这一点。我知道它是一个系统库,但除非安装了 Nuget,否则我不能使用它,所以我不知道这是否是一种特殊情况。在这两种情况下,我都使用 PowerShell Nuget 的 v6.1.1。
这是 Functions v2 的已知错误吗?还是我错过了什么?
【问题讨论】:
标签: azure powershell azure-functions