簡體   English   中英

如何從控制台運行Azure部署PowerShell腳本

[英]How to run an Azure deployment PowerShell script from console

我已經從Azure門戶下載了網站發布配置文件。 在Visual Studio中導入發布配置文件之后,我可以通過單擊ProjectName > Publish來發布我的網站而無需提供憑據。

導入產生的一系列文件

  • 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

我想知道是否可以在我的簡單部署過程中使用任何一個powershell文件。

當我嘗試運行xxxxx - Web Deploy-publish.ps1出現錯誤:

ps1:發布期間發生錯誤。 無法將參數綁定到參數'publishProperties',因為它為null。

我想我缺少一些參數。 有人可以為我提供一個如何正確運行的示例嗎?

這是一個示例Powershell,可用於將Web App部署到Azure。

您需要設置參數並指向您的發布設置,以獲取部署密碼等。

# 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 -------------------------------------------------------------------------------------------------------------------------------

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM