Function App 应用文件-requirements.psd1

Function App App files -requirements.psd1

创建函数应用程序(使用 Powershell 运行时)时,它会在“应用程序文件”中附带一个包含此内容的 requirements.psd1 文件

This file enables modules to be automatically managed by the Functions service.
See https://aka.ms/functionsmanageddependency for additional information.
@{
# For latest supported version, go to 'https://www.powershellgallery.com/packages/Az'.
# To use the Az module in your function app, please uncomment the line below.
# 'Az' = '6.'
}

AZ=6 行。已注释,有没有一种方法可以在部署时使用 ARM 模板或 Azure Powershell 取消注释此行?

我认为你不能在部署期间这样做,解决方法是在部署后通过 poweshell 中的 Kudu API 更新文件。

使用路径存储新的 requirements.psd1,例如C:\Users\Administrator\Desktop\requirements.psd1 在本地。

# This file enables modules to be automatically managed by the Functions service.
# See https://aka.ms/functionsmanageddependency for additional information.
#
@{
    # For latest supported version, go to 'https://www.powershellgallery.com/packages/Az'. 
    # To use the Az module in your function app, please uncomment the line below.
     'Az' = '6.*'
}

然后使用下面的脚本。

$appsvWebAppName = "<functionapp-name>"
$resourceGroupName = "<group-name>"

$resource = Invoke-AzResourceAction -ResourceGroupName $resourceGroupName -ResourceType Microsoft.Web/sites/config -ResourceName "$appsvWebAppName/publishingcredentials" -Action list -ApiVersion 2018-02-01 -Force

$username = $resource.Properties.publishingUserName
$password = $resource.Properties.publishingPassword
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $username, $password)))
$userAgent = "powershell/1.0"


$apiUrl = "https://$appsvWebAppName.scm.azurewebsites.net/api/vfs/site/wwwroot/requirements.psd1"
$filePath = "C:\Users\Administrator\Desktop\requirements.psd1"
$headers = @{
    'Authorization' = 'Basic ' + $base64AuthInfo
    'If-Match' = '*'
}
Invoke-RestMethod -Uri $apiUrl -Headers $headers -UserAgent $userAgent -Method PUT -InFile $filePath -ContentType "multipart/form-data"