asp.net - 如何从控制台运行 Azure 部署 PowerShell 脚本

标签 asp.net powershell azure deployment azure-powershell

我已从 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 : An error occurred during publish. Cannot bind argument to parameter 'publishProperties' because it is null.

我想我缺少一些参数。有人可以给我提供一个如何正确运行它的例子吗?

最佳答案

以下是一个示例 Powershell,可用于将 Web 应用程序部署到 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 -------------------------------------------------------------------------------------------------------------------------------

关于asp.net - 如何从控制台运行 Azure 部署 PowerShell 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34168007/

相关文章:

azure - 数据工厂 DevOps SSIS-IntegrationRuntime

c# - ToLocalTime() 中本地是如何确定的

powershell - 如何使用 Powershell 查询 msSFU30MaxUidNumber 属性?

azure - 如何将 docker 容器作为 Windows 服务运行

function - PowerShell哈希表返回值

PowerShell boolean 值接受所有数字

sql-server - Azure SQL 数据库表变量排序规则

asp.net - MVC 子操作在路径中抛出非法字符

asp.net - Facebook C# MVC MVC3 存储 token 以及 asp.net 成员(member)场景

asp.net - 动态初始化 ResourceManager