azure-functions - 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 取消注释此行?
解决方案
我认为您在部署期间不能这样做,解决方法是在部署后通过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"
推荐阅读
- react-native - 在 react-native 的其他组件中找不到变量导航
- python - 使用列表理解返回索引
- python - 在 sklearn python 中使用高斯过程回归时出错
- php - PHP:无法访问 JSON 对象/数组
- python - AttributeError:模块“jsapp.models”没有属性“User_Activity”
- selenium - Selenium Webdriver - 尝试通过xpath单击“更改为英语”链接但不起作用
- java - 我想使用java从这个XML树中提取所有标签
- sql - oracle SQL根据条件连接2列
- prometheus - Prometheus 长周期费率查询
- swift - 以编程方式更改 StackView 中按钮的宽度约束