0

I need a PowerShell script which will deploy an ASP.NET Core app's artifacts to Azure Web Service. Searching the Internet I managed to find this script:

param($websiteName, $packOutput)

$website = Get-AzureWebsite -Name $websiteName

Stop-AzureWebsite -Name $websiteName

# get the scm url to use with MSDeploy.  By default this will be the second in the array
$msdeployurl = $website.EnabledHostNames[1]

$publishProperties = @{'WebPublishMethod'='MSDeploy';
                        'MSDeployServiceUrl'=$msdeployurl;
                        'DeployIisAppPath'=$website.Name;
                        'Username'=$website.PublishingUsername;
                        'Password'=$website.PublishingPassword
                        }

$publishScript = "${env:ProgramFiles(x86)}\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\Microsoft\Web Tools\Publish\Scripts\1.2.0\default-publish.ps1"

. $publishScript -publishProperties $publishProperties -packOutput $packOutput

Start-AzureWebsite -Name $websiteName

I am using it the way it is shown on the screenshot: enter image description here

But...nothing happens as the result of msdeploy command execution: no errors, no data deployed...

So, what is the correct way of deploying ASP.NET Core artifacts with PowerShell?

1 Answer 1

1

Visual Studio could generate Windows PowerShell publish script for deploying to a website. The publish script may look like this.

publish script

[cmdletbinding(SupportsShouldProcess=$true)]
param($publishProperties=@{}, $packOutput, $pubProfilePath)

# to learn more about this file visit https://go.microsoft.com/fwlink/?LinkId=524327

try{
    if ($publishProperties['ProjectGuid'] -eq $null){
        $publishProperties['ProjectGuid'] = 'xxxxxxxx-0260-4800-b864-e9afa92d7fc2' 
    }

    $publishModulePath = Join-Path (Split-Path $MyInvocation.MyCommand.Path) 'publish-module.psm1'
    Import-Module $publishModulePath -DisableNameChecking -Force

    # call Publish-AspNet to perform the publish operation
    Publish-AspNet -publishProperties $publishProperties -packOutput $packOutput -pubProfilePath $pubProfilePath
}
catch{
    "An error occurred during publish.`n{0}" -f $_.Exception.Message | Write-Error
} 

And a publish module that contains functions that will be used in the scripts. For more information about publishscripts for deploying to a website, please refer to this documentation.

Sign up to request clarification or add additional context in comments.

1 Comment

I know VS generates the scripts, but I can't get them work. I tried the following command with VS script ./DemoDeploy - Web Publish-publish.ps1 -packOutput "Path to the website's artifacts" -pubProfilePath "Path to the profile generated by VS" . So, the results pretty the same as on the screenshot above. I've seen the provided link before, but it didn't help me too. I haven't seen the json file generated (which they use in the documentation), and the VS ps1 script doesn't seem to have the parameters they use in the examples. Could you please provide a usage example which does work?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.