Kudu Azure App Zip Deploy 通过 Powershell - 将文件传输到 wwwroot [英] Kudu Azure App Zip Deploy via Powershell - Transfer files to wwwroot
问题描述
我正在使用来自 powershell 的 Kudu Azure Zip Deploy API.
如何确保已部署的 zip 文件夹的内容在 wwwroot 中提取,而 wwwroot 是包含文件夹?
当前:
(这里我的 zip 文件夹是 wwwroot 中的容器)
/site/wwwroot/MYZIPFOLDERNAME/CONTENTS
预期:
(我希望将zip文件夹的内容直接添加到wwwroot和zip文件夹名称之外)
/site/wwwroot/CONTENTS
我遵循了如下所示的文档,并有一个如下所示的 powershell 脚本:
图 1.1.容器 xml
包含两个 xml 文件
图 2. zip 文件中没有容器 xml.zip
然后我使用具有不同文件结构的不同 zip 文件运行相同的 PowerShell 脚本,在我的 WebApp 的 ZipDeployUI
中得到不同的结果,如下图.
图 3. 运行带有容器 xml
的 zip 文件的 PowerShell 脚本,将 xml
容器解压到 wwwroot
>
图 3.1.wwwroot/xml
xml
中的两个xml文件图4. 使用没有容器的zip文件运行PowerShell脚本,将两个xml文件直接解压到wwwroot
因此,如果您使用的是诸如 7-zip
之类的工具,请直接将这些文件打包为 zip 文件,而不是打包它们的父目录.或者在 PowerShell 命令行中,请先 cd
移动到包含这些文件的目录,然后运行 Compress-Archive -Path * -DestinationPath
以获取 zip 文件,如 创建项目Zip文件
表示.
希望有帮助.
I am using the Kudu Azure Zip Deploy API from powershell.
How can I ensure that the contents of the deployed zip folder are extracted within wwwroot with wwwroot being the containing folder?
Current:
(here my zip folder is the container within wwwroot)
/site/wwwroot/MYZIPFOLDERNAME/CONTENTS
Expected:
(I want the contents of the zip folder to be added directly to wwwroot and outside of the zip folder name)
/site/wwwroot/CONTENTS
I have followed the documentation like below and have a powershell script like below:
https://docs.microsoft.com/en-us/azure/app-service/deploy-zip
#PowerShell
$username = "<deployment_user>"
$password = "<deployment_password>"
$filePath = "<zip_file_path>"
$apiUrl = "https://<app_name>.scm.azurewebsites.net/api/zipdeploy"
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $username, $password)))
$userAgent = "powershell/1.0"
Invoke-RestMethod -Uri $apiUrl -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -UserAgent $userAgent -Method POST -InFile $filePath -ContentType "multipart/form-data"
When the script is finished, the zipped file is uploaded to my site, however the content is packaged within the folder and nested under the wwwroot directory.
If I use the ZipDeployUI and drag the folder, it unzips into the wwwroot/ directory without the folder name as expected.
I followed the offical document Deploy your app to Azure App Service with a ZIP or WAR file
to run the PowerShell script in the subsection With PowerShell
, it's OK and works fine.
Your issue was caused by the file structure of your zip file. I will show you the difference.
There are two xml files in my directory D:\projects\xml
on local. I packaged them into a zip file xml.zip
using two different way: with a container xml
, without any container, as the figures below via 7-zip
.
Fig 1. a container xml
in the zip file xml.zip
Fig 1.1. the container xml
contains two xml files
Fig 2. no container in the zip file xml.zip
Then I run the same PowerShell script with different zip file which has different file structure, I got the different result in the ZipDeployUI
of my WebApp, as the figures below.
Fig 3. Run the PowerShell script with the zip file which has a container xml
, the xml
container be decompressed under wwwroot
Fig 3.1. the two xml files within the container xml
under the path wwwroot/xml
Fig 4. Run the PowerShell script with the zip file which has no container, the two xml files be decompressed directly under wwwroot
So please package these files directly to a zip file, not package their parent directory, if you were using some tools like 7-zip
. Or in the PowerShell command line, please first cd
move to the directory which contains these files you want to package, then to run Compress-Archive -Path * -DestinationPath <file-name>.zip
to get a zip file, as Create a project Zip file
said.
Hope it helps.
这篇关于Kudu Azure App Zip Deploy 通过 Powershell - 将文件传输到 wwwroot的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!