是否可以仅从命令行使用 non-admin 帐户 publish/deploy 网络包?

Is it possible to publish/deploy a web package, using a non-admin account, from the command line only?

标题需要一些扩展。总之,我发现不可能:

这一切似乎都归结为一个小细节,把一切都搞砸了,但我应该描述我的过程,直到一切都崩溃。

我在 VS 2013 中创建了一个发布配置文件 Publish,配置为发布到 Web 包。然后,我在开发人员命令提示符下执行以下命令:

msbuild Solution.sln /t:Build /p:DeployOnBuild=true;PublishProfile=Publish;IsDesktopBuild=false

这经历了一个构建过程,我现在在 _PublishedWebsites\Web_Package 文件夹中看到了预期的包和部署文件。我的下一步是 运行 来自 Web_Package 文件夹的这个:

Web.deploy.cmd /Y /M:https://example.blah:8172/MsDeploy.axd /U:user /P:p@44w0rd /A:Basic

这就是问题所在。这导致以下扩展命令(为便于阅读而格式化):

msdeploy.exe
    -source:package='.\Web.zip'
    -dest:auto,computerName="https://example.blah:8172/MsDeploy.axd",userName="user",password="p@44w0rd",authtype="Basic",includeAcls="False"
    -verb:sync 
    -disableLink:AppPoolExtension 
    -disableLink:ContentExtension 
    -disableLink:CertificateExtension 
    -setParamFile:".\Web.SetParameters.xml"

其执行结果:

Error Code: ERROR_USER_UNAUTHORIZED
More Information: Connected to the remote computer ("example.blah") 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.

我可以通过手动解决这个问题 re-running 只需扩展命令并将 site 参数标记到 MsDeploy.axd URL,如下所示:

msdeploy.exe
    -source:package='.\Web.zip'
    -dest:auto,computerName="https://example.blah:8172/MsDeploy.axd?site=example.blah",userName="user",password="p@44w0rd",authtype="Basic",includeAcls="False"
    -verb:sync 
    -disableLink:AppPoolExtension 
    -disableLink:ContentExtension 
    -disableLink:CertificateExtension 
    -setParamFile:".\Web.SetParameters.xml"

但是,我看不出有任何方法可以通过 Web.deploy.cmd 设置此设置,而 MSBuild 是 auto-generated。如果我试试这个:

Web.deploy.cmd /Y /M:https://example.blah:8172/MsDeploy.axd?site=example.blah /U:user /P:p@44w0rd /A:Basic

结果如下(同样,格式化以便于阅读):

msdeploy.exe
    -source:package='D:\DEV\Solution\Web\bin\_PublishedWebsites\Web_Package\Web.zip'
    -dest:auto,computerName="https://example.blah:8172/MsDeploy.axd?site",userName="user",password="p@44w0rd",authtype="Basic",includeAcls="False"
    -verb:sync 
    -disableLink:AppPoolExtension 
    -disableLink:ContentExtension 
    -disableLink:CertificateExtension 
    -setParamFile:"D:\DEV\Solution\Web\bin\_PublishedWebsites\Web_Package\Web.SetParameters.xml"  example.blah
Error: Unrecognized argument 'example.blah'. All arguments must begin with "-".
Error count: 1.

我可以使用管理员帐户很好地执行此过程。但似乎 non-admin 需要此 site= querystring 值,而 auto-generated Web.deploy.cmd 只是没有。

我是不是遗漏了什么明显的东西? IIS 管理方面是否缺少我的权限?我已确保按照指示设置了管理服务委派规则 in this blog post

我无法使用我列出的流程解决此问题。我这里的解决方案是简单地使用扩展的 MSDeploy.exe 命令行并直接使用它而不是生成的 *.deploy.cmd 文件。

当然,如果有人对我原来的问题提出了实际的解决方案,我会很乐意将 那个 标记为答案。在那之前,这是我的解决方案。

您可以将 /M: 参数放在引号中,如下所示:

Web.deploy.cmd /Y "/M:https://example.blah:8172/MsDeploy.axd?site=example.blah" /U:user /P:p@44w0rd /A:Basic