如何在ProjectName.deploy.cmd文件中传递sitename参数

7

我正在尝试运行由MSBuild生成的ProjectName.deploy.cmd文件,当参数/p:DeployOnBuild=True被传递时。其中一个参数“ComputerName”需要传递为https://WebServer01:8172/MSDeploy.axd?SiteName=MySiteName。我的命令行应该是:

ProjectName.deploy.cmd /Y /M:https://WebServer01:8172/MSDeploy.axd?Site=MySiteName 
                       -AllowUntrusted /U:DeployUserName /P:Password /A:Basic

它返回

Error: Unrecognized argument 'MySiteName'. All arguments must begin with "-".

实际执行的命令是:
"C:\Program Files\IIS\Microsoft Web Deploy V3\\msdeploy.exe" 
    -source:package='Y:\ProjectName.zip'
    -dest:auto,computerName='https://WebServer01:8172/MSDeploy.axd?Site',userName='DeployUserName',password='Password',authtype='Basic',includeAcls='False'
    -verb:sync -disableLink:AppPoolExtension -disableLink:ContentExtension 
    -disableLink:CertificateExtension 
    -setParamFile:"Y:\ProjectName.SetParameters.xml"
    MySiteName
    -AllowUntrusted

请注意,/M参数的参数值 https://WebServer01:8172/MSDeploy.axd?Site=MySiteName 被拆分为两个参数,从而创建了一个 computerName='https://WebServer01:8172/MSDeploy.axd?Site' 和一个额外的参数 MySiteName
我已经阅读了在Visual Studio 2010 Service Pack 1中使用带引号的参数运行部署包失败,但它只处理了 ArgMsDeployAdditionalFlags,而不是参数,例如 /M:ComputerName
当没有传递 SiteName 时,我可以使用具有服务器管理员权限的用户进行部署,但是当使用标准的IIS用户 DeployUserName 时,我会收到401错误。
ProjectName.deploy.cmd /Y /M:https://WebServer01:8172/MSDeploy.axd
                       -AllowUntrusted /U:DeployUserName /P:Password /A:Basic

服务器返回401。
Error Code: ERROR_USER_UNAUTHORIZED
More Information: Connected to the remote computer ("WebServer01") 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.

Error: The remote server returned an error: (401) Unauthorized.

该用户的权限是正确的,因为使用该用户从VS2012和使用MSDeploy配置文件发布工作得很好。我还可以构建msdeploy.exe命令,并且运行良好。我必须使用ProjectName.deploy.cmd,因为它是由TFS2010中的Team Build生成的一部分。

2个回答

9

您是否尝试过引用该参数?

ProjectName.deploy.cmd /Y "/M:https://WebServer01:8172/MSDeploy.axd?Site=MySiteName" 
                   -AllowUntrusted /U:DeployUserName /P:Password /A:Basic

那个问题是打错字了。我已经修正了它。问题不在于参数本身,而在于命令提示符处理“=”的方式,然后在deploy.cmd脚本中进一步传递给msdeploy.exe。 - amit_g
我确信我尝试过其他变体来避免等号,但那天它们都没有起作用:( 今天我从这个开始尝试,第一次就成功了。还有一些其他的安全问题,但那些都很简单。有了这个工作,我就不需要为部署用户获取管理员权限(这正是我想要的)。感谢@Richard的帮助。 - amit_g

3
我想为那些像我一样在尝试弄清楚为什么这不起作用的人添加答案,并提供等效的 MSDeploy 命令。如评论所述,引用参数将无法工作,因为存在参数解析错误,来自 MS 文档的说明如下:
“在撰写本文时,由于 Web Publishing Pipeline(WPP)中的一个错误,您不能使用包含查询字符串的端点地址运行 .deploy.cmd 文件。在此情况下,您需要直接使用 MSDeploy.exe 部署 Web 包。”
来源:https://learn.microsoft.com/en-us/aspnet/web-forms/overview/deployment/web-deployment-in-the-enterprise/deploying-web-packages 因此,您应该直接使用 MSDeploy。与问题中的 deploy.cmd 参数相当。
MSDeploy.exe -source:package='<fullPathToDeployable>\<projectName>.zip' 
-dest:auto,computerName="https://<ipOrDnsName>:8172/MSDeploy.axd",userName="<userName>",password="<pwd>",authtype="Basic",includeAcls="False" 
-verb:sync 
-disableLink:AppPoolExtension 
-disableLink:ContentExtension 
-disableLink:CertificateExtension 
-setParamFile:"<fullPathToDeployable>\<projectName>.SetParameters.xml"  
-setParam:name="IIS Web Application Name",value="<siteName>" 
-AllowUntrusted

(替换尖括号中的单词)


我需要 computerName=" https://<ipOrDnsName>:8172/MSDeploy.axd ?site=<siteName> *"*,以模拟Visual Studio的部署行为。非常感谢Martin!最终我成功地完成了我的部署。 - Chris Marisic

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接