MSDeploy batch file does not handle quotes anymore
Asked Answered
H

2

16

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(&quot;/Y /M:{0} -allowUntrusted&quot;, DeploymentServerName)]" DisplayName="Deploy selected Web Application using MSDeploy" EnvironmentVariables="[New Dictionary(Of String, String) From {{&quot;_MsDeployAdditionalFlags&quot;, DeploymentParameters}}]" FileName="[String.Format(&quot;{0}\Packages\{1}\{2} {3}\{4}.deploy.cmd&quot;, BuildDetail.DropLocation, platform.Configuration, ApplicationName, VersionString, DeploymentPackageName)]" sap:VirtualizedContainerService.HintSize="464,420" Result="[ExitCode]">
Harsho answered 4/4, 2011 at 14:28 Comment(0)
M
19

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.

Moleskins answered 20/4, 2011 at 18:12 Comment(7)
Thanks! Solved it by using the environment variables, but I will also fix it in the target file. Did not know that this was the place where the batch file was generated.Harsho
+1 I solved it by following the KB (as it should not have been introduced in the first place). Thanks!Syverson
@Moleskins can you please paste the correct lines into your answer so we can be sure if we have the right version or not? Is a restart required after downloading the new file? I still cannot publish after downloading it.Diatom
@Moleskins this is my related question, but using the deploy dialog, not a batch file: #8834478Diatom
The bug is still actual with VS 2012 and WebDeploy v3! It's ridiculously.Youthful
I used the new target file, and I can see it has generated slightly difference deploy.cmd file however I am still seeing "=" removed from extra args output. As if MSDEPLOY wasn't already a nightmare to use...Dennie
We've just updated to the VS2012 version and now the error is back again. Unfortunately the new target file seems vastly different than the new one, so I can't quite tell where to make changes.Actin
D
0

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'"
Dickdicken answered 10/12, 2013 at 20:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.