问题
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]">
回答1:
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.
回答2:
I was able to work around this issue by surrounding the whole argument in quotes and the inner argument in single quotes, ie:
.\Deploy.cmd /y
/m:https://SERVER:8172/msdeploy.axd
-allowUntrusted
"-postSync:runCommand='echo hello'"
来源:https://stackoverflow.com/questions/5539968/msdeploy-batch-file-does-not-handle-quotes-anymore