2016-11-18 189 views
2

我在Azure中使用Visual Studio部署/发布.Net Web应用程序的“Web应用程序”。 (生成 - >发布),它的工作原理。如何使用Powershell将.Net Web应用程序部署到Azure

我希望能够使用Powershell脚本部署/发布我的应用程序。我得到了下面的脚本程序生成部分工作:

CMD> "c:\Program Files (x86)\MSBuild\14.0\bin\msbuild.exe" WebApplication1.sln 

为了使它还部署,我需要添加一些参数:

CMD> "c:\Program Files (x86)\MSBuild\14.0\bin\msbuild.exe" WebApplication1.sln /p:DeployOnBuild=true /p:PublishProfile="C:\Users\jgodse\Documents\Visual Studio 2015\Projects\WebApplication1\WebApplication1\Properties\PublishProfiles\jg-7-web-app-1 - Web Deploy.pubxml" /p:Configuration=Release 

我得到了一个错误:

Build FAILED. 

"c:\Users\jgodse\Documents\Visual Studio 2015\Projects\WebApplication1\WebApplication1.sln" (default target) (1) -> 
"c:\Users\jgodse\Documents\Visual Studio 2015\Projects\WebApplication1\WebApplication1\WebApplication1.csproj" (default target) (2) -> 
(MSDeployPublish target) -> 
    C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\Web\Microsoft.Web.Publishing.targets(4295,5): msdeploy error ERROR_USER_UNAUTHORIZED: Web deployment task failed. (Connected to the remote computer ("jg-7-web-app-1.scm.azurewebsites.net") using the Web Management Service, but could not authorize. Make sure that you are using the correct user name and password, that the site you are connecting to exists, and that the credentials represent a user who has permissions to access the site. Learn more at: http://go.microsoft.com/fwlink/?LinkId=221672#ERROR_USER_UNAUTHORIZED.) [c:\Users\jgodse\Documents\Visual Studio 2015\Projects\WebApplication1\WebApplication1\WebApplication1.csproj] 

    0 Warning(s) 
    1 Error(s) 

我明显缺少Azure证书(因为Visual Studio能够捕获它们),而且我也没有在Powershell中运行。

所以我把整个命令,并把它变成一个名为DEPLOY.BAT文件,开辟了PowerShell窗口,并做了以下内容:

PS> Login-AzureRmAccount 

(我在用户名/密码的输入GUI弹出)。

PS> cmd /c .\deploy.bat 

构建没问题,但尝试发布时出现同样的错误。我猜这些Azure证书在CMD程序中退出时并未实现。

如何使用Powershell在我的.Net项目上调用MSBuild以发布到Azure Web应用程序?

回答

4

您可以使用现有的.pubxml文件,但需要密码才能部署。有几种方法可以获得它。其中最明显的就是导航到你的Web应用程序的刀片,然后点击“更多”,最后从门户网站得到它“获取发布配置文件”

enter image description here

此文件包含各种各样的数据,但您需要的数据称为userPWD - 这是您需要使用的密码。复制密码并将其添加到您的MsBuild命令中:

CMD>“c:\ Program Files(x86)\ MSBuild \ 14.0 \ bin \ msbuild.exe”WebApplication1.sln/p:DeployOnBuild = true/p:PublishProfile =“C:\ Users \ jgodse \ Documents \ Visual Studio 2015 \ Projects \ WebApplication1 \ WebApplication1 \ Properties \ PublishProfiles \ jg-7-web-app-1 - Web Deploy.pubxml”/ p:Configuration = Release /p:密码=不推荐“userPWD价值”

显然存储构建脚本这个值。您可以使用Powershell(Get-AzurePublishSettingsFile)下载发布设置,提取userPWD值,将其传递给MsBuild以发布您的应用程序,并最终清理所有内容。

有实现你建立的基础设施和我提出了可能不适合您的解决方案有什么不同的方式,但它是由你来尝试,并决定什么最适合你。

一些资源:

Automate Everything (Building Real-World Cloud Apps with Azure) - 这一个使用ASM,而不是资源管理器,但你可以很容易地调整它使用ARM Using Windows PowerShell scripts to publish to dev and test environments

希望这有助于。

+1

谢谢。那正是我需要的。 –

相关问题