如何将 .NET Core 3.x 与 Azure Function App Powershell 运行时一起使用?

How to use .NET Core 3.x with Azure Function App Powershell Runtime?

我在我的模板中使用以下资源创建了一个新的函数应用程序:

    {
      "apiVersion": "2015-08-01",
      "type": "Microsoft.Web/sites",
      "name": "[parameters('caAppName')]",
      "location": "[parameters('location')]",
      "kind": "functionapp",
      "dependsOn": [
        "[resourceId('Microsoft.Web/serverfarms', parameters('hostingPlanName'))]",
        "[resourceId('Microsoft.Storage/storageAccounts', variables('storageAccountName'))]"
      ],
      "identity": {
        "type": "SystemAssigned"
      },
      "properties": {
        "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', parameters('hostingPlanName'))]",
        "siteConfig": {
          "appSettings": [
            {
              "name": "AzureWebJobsStorage",
              "value": "[concat('DefaultEndpointsProtocol=https;AccountName=', variables('storageAccountName'), ';AccountKey=', listKeys(variables('storageAccountid'),'2015-05-01-preview').key1)]"
            },
            {
              "name": "WEBSITE_CONTENTAZUREFILECONNECTIONSTRING",
              "value": "[concat('DefaultEndpointsProtocol=https;AccountName=', variables('storageAccountName'), ';AccountKey=', listKeys(variables('storageAccountid'),'2015-05-01-preview').key1)]"
            },
            {
              "name": "WEBSITE_CONTENTSHARE",
              "value": "[toLower(parameters('caAppName'))]"
            },
            {
              "name": "FUNCTIONS_EXTENSION_VERSION",
              "value": "~3"
            },
            {
              "name": "WEBSITE_NODE_DEFAULT_VERSION",
              "value": "~10"
            },
            {
              "name": "APPINSIGHTS_INSTRUMENTATIONKEY",
              "value": "[reference(resourceId('microsoft.insights/components/', variables('applicationInsightsName')), '2015-05-01').InstrumentationKey]"
            },
            {
              "name": "FUNCTIONS_WORKER_RUNTIME",
              "value": "powershell"
            },
          ]
        }
      }

我 运行 门户中函数应用程序中的以下代码 Write-Host "$([System.Security.Cryptography.X509Certificates.X509Certificate2].Assembly.Location)"

我得到 D:\Program Files\dotnet\shared\Microsoft.NETCore.App.2.8\System.Security.Cryptography.X509Certificates.dll

但是如果我使用 Function App 控制台:

D:\Program Files\dotnet\shared\Microsoft.NETCore.App> ls
2.2.8
2.2.8.installed
3.0.3
3.0.3.installed
3.1.3
3.1.3.installed

所以 3.1.3 存在,但是函数没有用它执行。

我什至注意到是因为我尝试使用 System.Security.Cryptography.PbeParameters 并且缺少类型(以及其他一些 AsymmetricAlgorithm 内容)

我该如何解决这个问题?

.NET Core版本由Azure PowerShell worker决定,依赖于PowerShell SDK。 PowerShell 6 是 Azure Functions 目前唯一可用的版本,它依赖于 .NET Core 2.x,这就是为什么你的 PowerShell Function 是在这个上下文中执行的。为了使用 .NET Core 3.x,您有以下选择:

  • 推荐:等待Azure Functions对PowerShell 7的支持(预计在接下来的2-4周内部署);
  • 从您的 PowerShell 函数生成一个单独的可执行文件。