4

When publishing a ASP.NET 5 MVC 6 application to an Azure Web App using powershell, it seems that the published folder structure is somehow incorrect.

After the publish, the wwwroot is one folder too deep:

wwwroot dir

If I change the application's virtual directory from site\wwwroot to site\wwwroot\wwwroot, then it works!

First, I build and file publish using MSBuild:

/t:Build,FileSystemPublish /p:PublishConfiguration=$(BuildConfiguration) /p:PublishOutputPathNoTrailingSlash=$(build.stagingDirectory)

Second, publish to Azure Web App using this script and passing in $(build.stagingDirectory) as the $packOutput:

param([String] [Parameter(Mandatory = $true)]$websiteName, [String] [Parameter(Mandatory = $true)]$packOutput)

$SourceFolder    = "$packOutput"
[IO.DirectoryInfo] $parentDir = [System.IO.Path]::GetDirectoryName($packOutput)
$DestinationFile = "$parentDir\Publish.zip"
$Compression     = "Optimal"  # Optimal, Fastest, NoCompression

function Zip-Directory {
    Param(
      [Parameter(Mandatory=$True)][string]$DestinationFileName,
      [Parameter(Mandatory=$True)][string]$SourceDirectory = "",
      [Parameter(Mandatory=$False)][string]$CompressionLevel = "Optimal",
      [Parameter(Mandatory=$False)][switch]$IncludeParentDir
    )
    Add-Type -AssemblyName System.IO.Compression.FileSystem
    $CompressionLevel    = [System.IO.Compression.CompressionLevel]::$CompressionLevel  
    [System.IO.Compression.ZipFile]::CreateFromDirectory($SourceDirectory, $DestinationFileName, $CompressionLevel, $IncludeParentDir)
}

Zip-Directory -DestinationFileName $DestinationFile `
    -SourceDirectory $SourceFolder `
    -CompressionLevel $Compression ` #Optional parameter

Move-Item -Path $DestinationFile -Destination $SourceFolder\Publish.zip

Write-Output "Stopping web app..."
Stop-AzureWebsite -Name $websiteName

Write-Output "Publishing web app..."
Publish-AzureWebsiteProject -Name $websiteName -Package $SourceFolder\Publish.zip

Write-Output "Starting web app..."
Start-AzureWebsite -Name $websiteName

I cannot seem to see where this is all going wrong.

Edit: Using DNX beta6

Dave New
  • 38,496
  • 59
  • 215
  • 394
  • What is the directory structure inside your Publish.zip directory? – Shaun Luttin Sep 16 '15 at 16:18
  • 1
    @ShaunLuttin: It contains approot and wwwroot folders. – Dave New Sep 17 '15 at 13:37
  • 1
    Can we deduce that it then cannot be used with ASP.NET 5 applications? – Dave New Sep 17 '15 at 13:58
  • 1
    Seems to be the case. Though I a loathe to jump to conclusions, that's where I would put my money. ;-) The only other alternative is to figure out how to publish ASP.NET 5 Apps without needing the `approot` beside the `wwwroot`. I do not know how to do that. – Shaun Luttin Sep 17 '15 at 14:05
  • 1
    Fair enough :) Although approot contains the runtime, packages, the global.json, which are all needed as far as I understand. Thanks – Dave New Sep 17 '15 at 14:10
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/89927/discussion-between-shaun-luttin-and-davenewza). – Shaun Luttin Sep 17 '15 at 14:43

2 Answers2

2

The problem is that your Publish.zip folder will contain two subfolders. That will also be the case if you use the new dnu publish command that comes with .NET 5.

approot
wwwroot

Publish-AzureWebsiteProject publishes the contents of Publish.zip to the Azure Web App's site/wwwroot. What you need is a publish method that does not publish to site/wwwroot but instead publishes to /site, so that you end with the following directory structure in your Azure Web App.

D:\
  home 
    site
      approot
      wwwroot

An alternative is to push to the Azure Web App using Git or FTP instead of Publish-AzureWebsiteProject. Both give you the control you need and you use both from PowerShell. If you choose the Git route, while it will work out-of-the-box, also check out Project Kudu.

Push with Git

Community
  • 1
  • 1
Shaun Luttin
  • 133,272
  • 81
  • 405
  • 467
  • 1
    Can you suggest any solutions for this? – Dave New Sep 17 '15 at 03:38
  • Is it important to use PowerShell? What are the constraints for the solution? – Shaun Luttin Sep 17 '15 at 05:07
  • 1
    I don't believe there is a better alternative. This is on our CI build whereby we release to our development environment after every successful integration. We are using VSO's vNext build platform. Can you suggest anything else? – Dave New Sep 17 '15 at 05:41
1

Changing the application's virtual directory from site\wwwroot to site\wwwroot\wwwroot works once. After a next deploy your app's wwwroot folder will be located at

 site
  wwwroot
   wwwroot
    wwwroot

As a consequence you have to change the application's virtual directory to site\wwwroot\wwwroot\wwwroot to get any results in your browser. This process repeats itself for every following deployment. You can prevent this by adding a extra virtual directory to the azure website. In case of an API it would look like this:

/    site\wwwroot
/api site\wwwroot\wwwroot

Publish-AzureWebsiteProject will keep deploying to site\wwwroot and you can access your application in the browser at something.com/api