msbuild部署在python中失败,但在控制台上运行

时间:2015-02-15 00:13:17

标签: python visual-studio-2013 msbuild

我在运行部署时遇到msbuild的奇怪行为。通过subprocess.Popen()从Python脚本中调用它时,调用失败并返回ERROR_USER_UNAUTHORIZED。但是,我打印到控制台确切的命令被触发。如果我复制&将确切的commant粘贴到Windows控制台中,msbuild命令完美地运行。来自Python内部的调用有什么问题(注意:设置Shell = False在这种情况下不会改变任何内容)。这适用于带有VisualStudio 2013的msbuild。

这是Python代码:

    # Execute. "action" is list of strings.
    def execute(self, action):
        # Execute the subprocess and connect stdout pipe.
        # Redirect stderr to also stream to stdout
        p = subprocess.Popen(action, bufsize=1, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=True)

        # Continuously read process output and write to log window
        lines_iterator = iter(p.stdout.readline, b'')

        # Fetch lines from pipe while child is running
        while p.poll() is None:
            for line in lines_iterator:
                self.add_log(line.decode('cp850'))

        # Returncode will be 0 if everything went fine. Note that a build error
        # results in a nonzero result code always (no exception)
        if p.returncode != 0:
            raise Exception("Command returned nonzero exit code")

这是发送给msbuild的(匿名)命令:

msbuild.exe
  myproj.csproj
  /P:Platform=AnyCPU
  /P:UserName=publish
  /P:Password=****
  /P:DeployOnBuild=True
  /P:DeployTarget=MSDeployPublish
  /P:AllowUntrustedCertificate=True
  /P:MSDeployPublishMethod=WMSvc
  /P:CreatePackageOnPublish=True
  /v:quiet
  /P:MsDeployServiceUrl=<my url>/MsDeploy.axd
  /P:DeployIisAppPath="my_app_path"
  /P:Configuration=Release

这是确切的错误消息(不幸的是德语):

C:\ Program Files(x86)\ MSBuild \ Microsoft \ VisualStudio \ v12.0 \ Web \ Microsoft.Web.Publishing.targets(4255,5):msdeploy错误ERROR_USER_UNAUTHORIZED:Web部署任务失败。 (Die Verbindung mit dem Remotecomputer(“”)wurde mit dem Webverwaltungsdienst hergestellt,eine Autorisierung war jedochnichtmöglich.StellenSie sicher,dass Sie den korrekten Benutzernamen und das korrekte Kennwort verwenden,dass die Website,mit der eine Verbindung hergestellt werden soll, vorhanden ist und dass die Anmeldeinformationen einen Benutzer darstellen,derfürdenZugriff auf die Website berechtigt ist。

在英语中,它基本上说它可以到达服务器,但无法授权。

1 个答案:

答案 0 :(得分:0)

与此同时,我有一个解决方法。 python脚本将完整命令(因此:&#34;&#34; .join(arglist))写入批处理文件并执行批处理文件(Shell = True)。这有效。仍然不知道为什么直接部署调用总是失败。