首页 > 解决方案 > Function App 应用程序文件 -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 取消注释此行?

标签: azure-functionsazure-resource-managerazure-template

解决方案


我认为您在部署期间不能这样做,解决方法是在部署后通过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"

推荐阅读