我在Azure上有一个“Web应用程序”,我使用Visual Studio部署/发布.Net Web应用程序(构建 -> 发布),并且它可以正常工作。
我希望能够使用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
构建过程顺利完成,但在尝试发布时出现了相同的错误。我猜测,在调用CMD程序时,Azure凭据并未传递。
我该如何使用PowerShell调用MSBuild来发布我的.NET项目到Azure Web应用程序?