1
votes

I've downloaded a website publish profile form Azure Portal. After importing the publish profile in Visual Studio I can publish my website without providing credentials by clicking ProjectName > Publish.

Importing produced a series of files

  • xxxxx - FTP.pubxml
  • xxxxx - FTP.pubxml.user
  • xxxxx - FTP-publish.ps1
  • xxxxx - Web Deploy.pubxml
  • xxxxx - Web Deploy.pubxml.user
  • xxxxx - Web Deploy-publish.ps1

I'm wondering if I could use either of the powershell files in my simple deployment process.

When I tried to run xxxxx - Web Deploy-publish.ps1 i got an error:

ps1 : An error occurred during publish. Cannot bind argument to parameter 'publishProperties' because it is null.

I guess I'm missing some parameters. Can somebody provide me with an example how to run it properly?

1

1 Answers

1
votes

Here is a sample Powershell that you can use to deploy your Web App to Azure.

You need to set the Params and point to your publish settings to get the deploy password etc..

# How to run the script
# deploy-azure-website-devbox-webdeploy.ps1 -ProjectFile

# Define input parameters
Param(
    [Parameter(Mandatory = $true)]
    [String]$ProjectFile,          # Point to the .csproj file of the project you want to deploy

    [Switch]$Launch                # Use this switch parameter if you want to launch a browser to show the website
)

# Begin - Actual script -----------------------------------------------------------------------------------------------------------------------------

# Set the output level to verbose and make the script stop on error
$VerbosePreference = "Continue"
$ErrorActionPreference = "Stop"

$scriptPath = Split-Path -parent $PSCommandPath

# Mark the start time of the script execution
$startTime = Get-Date

# Build and publish the project via web deploy package using msbuild.exe 

Write-Verbose ("[Start] deploying to Windows Azure website {0}" -f $websiteName)

# Read from website-environment.xml to get the environment name
[Xml]$envXml = Get-Content ("{0}\website-environment.xml" -f $scriptPath)
$websiteName = $envXml.environment.name

# Read from the publish settings file to get the deploy password
$publishXmlFile = "{0}\{1}.pubxml" -f $scriptPath, $websiteName
[Xml]$xml = Get-Content ("{0}\{1}.publishsettings" -f $scriptPath, $websiteName)
$password = $xml.publishData.publishProfile.userPWD.get(0)

# Run MSBuild to publish the project
& "$env:windir\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe" $ProjectFile `
    /p:VisualStudioVersion=11.0 `
    /p:DeployOnBuild=true `
    /p:PublishProfile=$publishXmlFile `
    /p:Password=$password

Write-Verbose ("[Finish] deploying to Windows Azure website {0}" -f $websiteName)

# Mark the finish time of the script execution
$finishTime = Get-Date

# Output the time consumed in seconds
Write-Output ("Total time used (seconds): {0}" -f ($finishTime - $startTime).TotalSeconds)

# Launch the browser to show the website
If ($Launch)
{
    Show-AzureWebsite -Name $websiteName
}

# End - Actual script -------------------------------------------------------------------------------------------------------------------------------