【发布时间】:2018-05-05 18:13:35
【问题描述】:
我在应用服务中部署了文件。我想在文件中更新字符串 stringToReplace。
stringToReplace
- 不想重新部署
- 想要使用 powershell 更新文件字符串(不是手动)
【问题讨论】:
-
如果是config文件,可以尝试使用kudu更新文件。
标签: azure azure-web-app-service paas
我在应用服务中部署了文件。我想在文件中更新字符串 stringToReplace。
stringToReplace
【问题讨论】:
标签: azure azure-web-app-service paas
看来我们没有办法直接用 powershell 做到这一点。您可以将your idea 提供给 Azure WebApp 团队。
- 不想重新部署
- 想要使用 powershell 更新文件字符串(不是手动)
根据我的经验,我建议您可以使用 Azure Kudu VFS API 获取文件内容并替换您想要的字符串并将其放入新内容以在 Azure 上归档。然后您将无需重新部署 azure webapp,只需更新您想要的单个文件..
GET /api/vfs/{path}
Gets a file at path
PUT /api/vfs/{path}
Puts a file at path.
如何在powershell中使用Azure Kudu Rest API你可以参考这个blog。以下是来自博客的sn-p代码
获取 API 授权:
function Get-KuduApiAuthorisationHeaderValue($resourceGroupName, $webAppName){
$publishingCredentials = Get-PublishingProfileCredentials $resourceGroupName $webAppName
return ("Basic {0}" -f [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $publishingCredentials.Properties.PublishingUserName, $publishingCredentials.Properties.PublishingPassword))))
}
上传单个文件
function Upload-FileToWebApp($kuduApiAuthorisationToken, $webAppName, $fileName, $localPath ){
$kuduApiUrl = "https://$webAppName.scm.azurewebsites.net/api/vfs/site/wwwroot/app/resources/$fileName"
$result = Invoke-RestMethod -Uri $kuduApiUrl `
-Headers @{"Authorization"=$kuduApiAuthorisationToken;"If-Match"="*"} `
-Method PUT `
-InFile $localPath `
-ContentType "multipart/form-data"
}
【讨论】: