MSDeploy 批处理文件不再处理引号
作为构建过程的一部分,我们使用 MSDeploy 部署 Web 应用程序。直到几周前,这一切都还很完美(我想当我们将构建/TFS 服务器更新到 TFS 2010 的 SP1 时)。
在我们的构建定义中,有一个调用流程的步骤。此过程将调用生成的deploy.cmd 文件并传入几个附加参数。这在很长一段时间内都工作得很好,但现在我们得到了这个:
错误:无法识别的参数'“-skip:objectName = filePath,absolutePath =。* cmsservices.config”'。所有参数必须以“-”开头。
如帮助中所述,我们用引号传递附加参数:
WebApplication.deploy.cmd /Y /M:sv-ad-iis02 -allowUntrusted "-skip:objectName=filePath,absolutePath=.*cmsservices.config" "-skip :objectName=filePath,absolutePath=.*servicemodel.client.config" "-skip:objectName=dirPath,absolutePath=app_data"
但是,这个技巧不再有效。删除引号也会删除所有字符,例如 = 和 ,这些字符将被空格替换。
我将其追溯到(通过将旧的部署.cmd 与新版本进行比较)到这一行:
第 76 行:
@rem Any addition flags, pass through to the msdeploy
set _ArgMsDeployAdditionalFlags=%_ArgMsDeployAdditionalFlags% %_ArgCurrentOriginal%
在以前的版本中,这是:
@rem Any addition flags, pass through to the msdeploy
set _ArgMsDeployAdditionalFlags=%_ArgMsDeployAdditionalFlags% %_ArgCurrent%
_ArgCurrentOriginal 使用 %1 而不是 % ~1 如果我更改此代码,一切都会再次起作用。然而,deploy.cmd 文件每次都是自动生成的(至少看起来像)
任何线索为什么会改变以及如何处理这个问题?
更新;我通过使用环境变量传递这些值来解决这个问题。它仍然没有解决新的deploy.cmd文件以不同的方式转义引号的问题。
我现在将解决方案放入部署流程工作流程中:
<mtbwa:InvokeProcess Arguments="[String.Format("/Y /M:{0} -allowUntrusted", DeploymentServerName)]" DisplayName="Deploy selected Web Application using MSDeploy" EnvironmentVariables="[New Dictionary(Of String, String) From {{"_MsDeployAdditionalFlags", DeploymentParameters}}]" FileName="[String.Format("{0}\Packages\{1}\{2} {3}\{4}.deploy.cmd", BuildDetail.DropLocation, platform.Configuration, ApplicationName, VersionString, DeploymentPackageName)]" sap:VirtualizedContainerService.HintSize="464,420" Result="[ExitCode]">
As part of our build process we deploy our web applications using MSDeploy. This worked perfect until a few weeks ago (I think when we updated our build/TFS server to SP1 of TFS 2010).
In our build definition there is a step to invoke a process. This process will call the generated deploy.cmd file and passes in a couple of additional parameters. This worked fine for a long time, but now we get this:
Error: Unrecognized argument '"-skip:objectName=filePath,absolutePath=.*cmsservices.config"'. All arguments must begin with "-".
As described in the help we pass the additional arguments in with quotes:
WebApplication.deploy.cmd /Y /M:sv-ad-iis02 -allowUntrusted "-skip:objectName=filePath,absolutePath=.*cmsservices.config" "-skip:objectName=filePath,absolutePath=.*servicemodel.client.config" "-skip:objectName=dirPath,absolutePath=app_data"
However, this trick does no longer works. Removing the quotes will also remove any characters like = and , which will be replaced by spaces.
I traced it back (by comparing an old deploy.cmd with a new version) to this line:
Line 76:
@rem Any addition flags, pass through to the msdeploy
set _ArgMsDeployAdditionalFlags=%_ArgMsDeployAdditionalFlags% %_ArgCurrentOriginal%
In the previous version this was:
@rem Any addition flags, pass through to the msdeploy
set _ArgMsDeployAdditionalFlags=%_ArgMsDeployAdditionalFlags% %_ArgCurrent%
The _ArgCurrentOriginal uses the %1 instead of %~1 and if I change this code, it all works again. However the deploy.cmd file is auto generated each time (at least it looks like)
Any clue why this has been changed and how to deal with this?
Update; I worked around this problem by using the environment variable to pass in these values. It still does not solve the issue that the new deploy.cmd files are escaping quotes in a different way.
The solution I now placed in my deploy process workflow:
<mtbwa:InvokeProcess Arguments="[String.Format("/Y /M:{0} -allowUntrusted", DeploymentServerName)]" DisplayName="Deploy selected Web Application using MSDeploy" EnvironmentVariables="[New Dictionary(Of String, String) From {{"_MsDeployAdditionalFlags", DeploymentParameters}}]" FileName="[String.Format("{0}\Packages\{1}\{2} {3}\{4}.deploy.cmd", BuildDetail.DropLocation, platform.Configuration, ApplicationName, VersionString, DeploymentPackageName)]" sap:VirtualizedContainerService.HintSize="464,420" Result="[ExitCode]">
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是 SP1 版本中引入的错误。您可以通过编辑
%ProgramFiles(x86)%\MSBuild\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.targets
(注意 64 位路径)来解决此问题。更改第3238-3258行以匹配旧deploy.cmd文件中的相应内容; diff 应该只有 3 行,删除 _ArgCurrentOriginal 并使用 _ArgCurrent。最近还发布了有关此问题的知识库:http://support.microsoft.com/kb/2537134。其中包括更新的 .targets 文件,因此您不必自己进行编辑。
This is a bug introduced in the SP1 release. You can work around it by editing
%ProgramFiles(x86)%\MSBuild\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.targets
(note 64-bit path). Change lines 3238-3258 to match the respective contents in the old deploy.cmd file; the diff should only be like 3 lines, removing _ArgCurrentOriginal and using _ArgCurrent.There's also a KB recently published on the issue: http://support.microsoft.com/kb/2537134. This includes an updated .targets file so you don't have to make the edit yourself.
我能够通过将整个参数用引号括起来并将内部参数用单引号括起来来解决这个问题,即:
I was able to work around this issue by surrounding the whole argument in quotes and the inner argument in single quotes, ie: