Azure 的默认教程介绍了如何从头开始创建项目,并将其部署到 Azure 云服务。我在尝试部署现有项目时遇到了意想不到的问题。
所以,我所拥有的是存储在 GIT 中的几个项目的 Web 解决方案。在解决方案内部有一个主项目,其中包含所有关系,并且在构建该项目的文件夹后准备部署到服务器。
问题是 - 如何为 Azure 部署配置项目,并通过 CLI 工具为其构建部署包?
Azure 的默认教程介绍了如何从头开始创建项目,并将其部署到 Azure 云服务。我在尝试部署现有项目时遇到了意想不到的问题。
所以,我所拥有的是存储在 GIT 中的几个项目的 Web 解决方案。在解决方案内部有一个主项目,其中包含所有关系,并且在构建该项目的文件夹后准备部署到服务器。
问题是 - 如何为 Azure 部署配置项目,并通过 CLI 工具为其构建部署包?
经过一段时间的研究,我找到了一个可行的解决方案。
旧网站解决方案应该准备一点:
Cloud -> Azure Project
,但不要在此步骤中选择角色;在此步骤中,您可以从 Visual Studio 的下拉菜单(如“发布...”或“包...”)部署解决方案。但首先配置您的角色。
要使包自动部署,只需执行此处描述的脚本即可。这是我发现的最干净的脚本,它正在制定任何 Azure SDK 的部署过程。
要自动打包项目,只需运行以下 powershell 脚本:
$project = resolve-path ".\..\relative\path\to\azure\deploy\project.ccproj"
Import-Module -Name ".\Invoke-MsBuild.psm1"
$buildSucceeded = Invoke-MsBuild -Path $project -P '/p:configuration=release /p:overwritereadonlyfiles=true /p:targetprofile="Cloud" /target:Clean;Publish'
if ($buildSucceeded)
{ Write-Host "Build completed successfully." }
else
{ Write-Host "Build failed. Check the build log file for errors." }
对于此脚本,您将需要Invoke-MsBuild。
It's absolutely possible. If using Azure Websites, you can do a git-deploy, dropbox, etc. If Cloud Services (web role), you can build via visual studio (IDE or command line), then deploy the package with PowerShell.
EDIT Quick example using PowerShell, to create a cloud service locally (via New-AzureServiceProject and [Add-AzureWebRole(http://msdn.microsoft.com/en-us/library/windowsazure/dn205203.aspx)):
New-AzureServiceProject -ServiceName myservice
Add-AzureWebRole -Name MyWebRole
You can add your code to the created web role and use msbuild to build it (and cspack to package it). You can then deploy your built package with PowerShell, via New-AzureDeployment:
New-AzureDeployment -ServiceName "mynewservice" -Slot "production -Package packagepath -Configuration configpath -Label "my service deployment"
Note that with the package and configuration paths, they can either be local or in a blob (and you'd need to upload them to blobs before calling New-AzureDeployment
). Also look at Publish-AzureServiceProject.
Note: The Azure PowerShell cmdlet reference is here. But... if you type get-help *azure*
at the PS command line, you'll see the latest cmdlets, and you can then look at help for individual cmdlets).
Beyond that, I'm not sure exactly what you're looking for. But I strongly suggest spending some time with the command-line tools + documentation, as well as running through a few basic tutorials on asp.net + Azure, such as this one for Web Sites and this one for Cloud Services (in particular, the intro video).