2
votes

I'm attempting to update a deployment process for a .NET Framework site to an Azure WebApp. We were previously using the Publish-AzureWebsiteProject PowerShell cmdlet but it's being phased out. So we're attempting to use kudu's zipdeploy functionality via the recently released Publish-AzWebApp PowerShell cmdlet. Everything's working great as far as getting the files to Azure, but failing horribly in unpacking the ZIP into to the correct location.

When I build the site using the "Package" target on our build server it produces a ZIP structured for use with MSDeploy. This is not the format expected by the zipdeploy method. The MSDeploy ZIP file includes deployment XML, and the actual content is deep-nested into a path representing the original location. Zipdeploy appears to want a simple archive of the web site's content root and so it's copying the files from the archive into the literal path after extraction.

So, for example, if my Visual Studio solution is in d:\builds\solution then the build files for packaging are put in d:\builds\solution\project\obj\debug\Package\PackageTemp. The content of the site goes into the ZIP under the following path D_C\builds\solution\project\obj\debug\Package\PackageTemp\Content. As a result, when zipdeploy runs it's putting the content into the webapp at wwwroot/Content/D_C/builds/solution/project/obj/debug/Package/PackageTemp/Content/.

The command I'm running to build the project is:

msbuild.exe /nologo /v:minimal /T:Package /p:Configuration="Debug;VisualStudioVersion=12.0" project.csproj

I'm hoping somebody knows how I can achieve this with one of the following (preferential order):

  • a msbuild argument to build the site and create a simple content ZIP
  • a kudu setting that will deploy the current ZIP using msdeploy instead of straight copy
  • a custom kudu deployment script that will deploy via msdeploy instead of file copy
  • a msbuild target customization that will create a compatible ZIP
2

2 Answers

1
votes

I realise this is an old post, but I also had this problem using Powershell to zipdeploy Azure Functions. In my case the existing Azure Functions were removed, but the new ones were not created. I was using Compress-Archive to create the deploy package. If I created the package with 7Zip instead it worked fine. That was on Powershell v5.1.18362.752

Running the same code on Powershell 7.0.3 worked fine. I have not tried PowerSHell 6. Here is the code snippet:

$files = Get-ChildItem -Path $path -Exclude $exclude
# check the powershell version because v5.1 has a Compress-Archive that won't deploy to Azure
if($PSVersionTable.PSVersion.Major -lt 7){
    Write-Host -ForegroundColor Red "Incompatible PowerShell version."
    return
}
# compress
Compress-Archive -Path $files -DestinationPath $publish_archive -CompressionLevel Optimal

$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add("Authorization", ("Basic {0}" -f $base64AuthInfo))
$headers.Add("Content-Type", "application/zip")

$ret = Invoke-RestMethod -Method Post -Headers $headers -Uri $url -InFile $publish_archive

$publish_archive is the FULL path to the zip file (not a relative path)

-1
votes

I understand that you are trying CI CD pipeline to deploy a web application in Azure Web apps.

Below URL will help you in deploying Zip

https://docs.microsoft.com/en-us/azure/app-service/deploy-zip

Note : MSBUILD Zip may not work through all deployment models

Zip config MSBuild.exe /p:configuration="release";platform="any cpu";WebPublishMethod=Package;PackageFileName="\MyFolder\package.zip";DesktopBuildPackageLocation="\MyFolder\package.zip";PackageAsSingleFile=true;PackageLocation="\MyFolder\package.zip";DeployOnBuild=true;DeployTarget=Package