CCS.deploy.cmd 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. @rem ---------------------------------------------------------------------------------
  2. @rem This is provided as sample to deploy the package using msdeploy.exe
  3. @rem For information about IIS Web Deploy technology,
  4. @rem please visit https://go.microsoft.com/?linkid=9278654
  5. @rem Note: This batch file assumes the package and setparameters.xml are in the same folder with this file
  6. @rem ---------------------------------------------------------------------------------
  7. @if %_echo%!==! echo off
  8. setlocal
  9. @rem ---------------------------------------------------------------------------------
  10. @rem Please Make sure you have Web Deploy install in your machine.
  11. @rem Alternatively, you can explicit set the MsDeployPath to the location it is on your machine
  12. @rem set MSDeployPath="C:\Program Files (x86)\IIS\Microsoft Web Deploy V3\"
  13. @rem ---------------------------------------------------------------------------------
  14. @rem ---------------------------------------------------------------------------------
  15. @rem if user does not set MsDeployPath environment variable, we will try to retrieve it from registry.
  16. @rem ---------------------------------------------------------------------------------
  17. if "%MSDeployPath%" == "" (
  18. for /F "usebackq tokens=1,2,*" %%h in (`reg query "HKLM\SOFTWARE\Microsoft\IIS Extensions\MSDeploy" /s ^| findstr -i "InstallPath"`) do (
  19. if /I "%%h" == "InstallPath" (
  20. if /I "%%i" == "REG_SZ" (
  21. if not "%%j" == "" (
  22. if "%%~dpj" == "%%j" (
  23. set MSDeployPath=%%j
  24. ))))))
  25. @rem ------------------------------------------
  26. @rem ------------------------------------------
  27. if not exist "%MSDeployPath%msdeploy.exe" (
  28. echo. msdeploy.exe is not found on this machine. Please install Web Deploy before execute the script.
  29. echo. Please visit https://go.microsoft.com/?linkid=9278654
  30. goto :usage
  31. )
  32. set RootPath=%~dp0
  33. if /I "%_DeploySetParametersFile%" == "" (
  34. set _DeploySetParametersFile=%RootPath%CCS.SetParameters.xml
  35. )
  36. @rem ------------------------------------------
  37. @rem ------------------------------------------
  38. set _ArgTestDeploy=
  39. set _ArgDestinationType=auto
  40. set _ArgComputerNameWithQuote=""
  41. set _ArgUserNameWithQuote=""
  42. set _ArgPasswordWithQuote=""
  43. set _ArgEncryptPasswordWithQuote=""
  44. set _ArgIncludeAclsWithQuote="False"
  45. set _ArgAuthTypeWithQuote=""
  46. set _ArgtempAgentWithQuote=""
  47. set _ArgLocalIIS=
  48. set _ArgLocalIISVersion=
  49. set _HaveArgMSDeployAdditonalFlags=
  50. @rem ---------------------------------------------------------------------------------
  51. @rem Simple Parse the arguments
  52. @rem ---------------------------------------------------------------------------------
  53. :NextArgument
  54. set _ArgCurrent=%~1
  55. set _ArgFlagFirst=%_ArgCurrent:~0,1%
  56. set _ArgFlag=%_ArgCurrent:~0,3%
  57. set _ArgValue=%_ArgCurrent:~3%
  58. if /I "%_ArgFlag%" == "" goto :GetStarted
  59. if /I "%_ArgFlag%" == "~0,3" goto :GetStarted
  60. if /I "%_ArgFlag%" == "/T" set _ArgTestDeploy=true&goto :ArgumentOK
  61. if /I "%_ArgFlag%" == "/Y" set _ArgTestDeploy=false&goto :ArgumentOK
  62. if /I "%_ArgFlag%" == "/L" set _ArgLocalIIS=true&goto :ArgumentOK
  63. if /I "%_ArgFlag%" == "/M:" set _ArgComputerNameWithQuote="%_ArgValue%"&goto :ArgumentOK
  64. if /I "%_ArgFlag%" == "/U:" set _ArgUserNameWithQuote="%_ArgValue%"&goto :ArgumentOK
  65. if /I "%_ArgFlag%" == "/P:" set _ArgPasswordWithQuote="%_ArgValue%"&goto :ArgumentOK
  66. if /I "%_ArgFlag%" == "/E:" set _ArgEncryptPasswordWithQuote="%_ArgValue%"&goto :ArgumentOK
  67. if /I "%_ArgFlag%" == "/I:" set _ArgIncludeAclsWithQuote="%_ArgValue%"&goto :ArgumentOK
  68. if /I "%_ArgFlag%" == "/A:" set _ArgAuthTypeWithQuote="%_ArgValue%"&goto :ArgumentOK
  69. if /I "%_ArgFlag%" == "/G:" set _ArgtempAgentWithQuote="%_ArgValue%"&goto :ArgumentOK
  70. @rem Any addition flags, pass through to the msdeploy
  71. if "%_HaveArgMSDeployAdditonalFlags%" == "" (
  72. goto :Assign_ArgMsDeployAdditionalFlags
  73. )
  74. set _ArgMsDeployAdditionalFlags=%_ArgMsDeployAdditionalFlags:&=^&% %_ArgCurrent:&=^&%
  75. set _HaveArgMSDeployAdditonalFlags=1
  76. goto :ArgumentOK
  77. :Assign_ArgMsDeployAdditionalFlags
  78. set _ArgMsDeployAdditionalFlags=%_ArgCurrent:&=^&%
  79. set _HaveArgMSDeployAdditonalFlags=1
  80. goto :ArgumentOK
  81. :ArgumentOK
  82. shift
  83. goto :NextArgument
  84. :GetStarted
  85. @rem ------------------------------------------
  86. @rem ------------------------------------------
  87. if /I "%_ArgTestDeploy%" == "" goto :usage
  88. if /I "%_ArgDestinationType%" == "" goto :usage
  89. set _Destination=%_ArgDestinationType%
  90. if not %_ArgComputerNameWithQuote% == "" set _Destination=%_Destination%,computerName=%_ArgComputerNameWithQuote%
  91. if not %_ArgUserNameWithQuote% == "" set _Destination=%_Destination%,userName=%_ArgUserNameWithQuote%
  92. if not %_ArgPasswordWithQuote% == "" set _Destination=%_Destination%,password=%_ArgPasswordWithQuote%
  93. if not %_ArgAuthTypeWithQuote% == "" set _Destination=%_Destination%,authtype=%_ArgAuthTypeWithQuote%
  94. if not %_ArgEncryptPasswordWithQuote% == "" set _Destination=%_Destination%,encryptPassword=%_ArgEncryptPasswordWithQuote%
  95. if not %_ArgIncludeAclsWithQuote% == "" set _Destination=%_Destination%,includeAcls=%_ArgIncludeAclsWithQuote%
  96. if not %_ArgtempAgentWithQuote% == "" set _Destination=%_Destination%,tempAgent=%_ArgtempAgentWithQuote%
  97. @rem ------------------------------------------
  98. @rem ------------------------------------------
  99. @rem ---------------------------------------------------------------------------------
  100. @rem add -whatif when -T is specified
  101. @rem ---------------------------------------------------------------------------------
  102. if /I "%_ArgTestDeploy%" NEQ "false" (
  103. set _MsDeployAdditionalFlags=-whatif %_MsDeployAdditionalFlags%
  104. )
  105. @rem ------------------------------------------
  106. @rem ------------------------------------------
  107. @rem ---------------------------------------------------------------------------------
  108. @rem add flags for IISExpress when -L is specified
  109. @rem ---------------------------------------------------------------------------------
  110. if /I "%_ArgLocalIIS%" == "true" (
  111. call :SetIISExpressArguments
  112. )
  113. if /I "%_ArgLocalIIS%" == "true" (
  114. if not exist "%IISExpressPath%%IISExpressManifest%" (
  115. echo. IISExpress is not found on this machine. Please install through Web Platform Installer before execute the script.
  116. echo. or remove /L flag
  117. echo. Please visit https://go.microsoft.com/?linkid=9278654
  118. goto :usage
  119. )
  120. if not exist "%IISExpressUserProfileDirectory%" (
  121. echo. %IISExpressUserProfileDirectory% is not exists
  122. echo. IISExpress is found on the machine. But the user have run IISExpress at least once.
  123. echo. Please visit https://go.microsoft.com/?linkid=9278654 for detail
  124. goto :usage
  125. )
  126. set _MsDeployAdditionalFlags=%_MsDeployAdditionalFlags% -appHostConfigDir:%IISExpressUserProfileDirectory% -WebServerDir:"%IISExpressPath%" -webServerManifest:"%IISExpressManifest%"
  127. )
  128. @rem ---------------------------------------------------------------------------------
  129. @rem check the existence of the package file
  130. @rem ---------------------------------------------------------------------------------
  131. if not exist "%RootPath%CCS.zip" (
  132. echo "%RootPath%CCS.zip" does not exist.
  133. echo This batch file relies on this deploy source file^(s^) in the same folder.
  134. goto :usage
  135. )
  136. @rem ---------------------------------------------
  137. @rem ---------------------------------------------
  138. @rem ---------------------------------------------------------------------------------
  139. @rem Execute msdeploy.exe command line
  140. @rem ---------------------------------------------------------------------------------
  141. call :CheckParameterFile
  142. echo. Start executing msdeploy.exe
  143. echo -------------------------------------------------------
  144. if not exist "%_DeploySetParametersFile%" (
  145. set _MSDeployCommandline="%MSDeployPath%msdeploy.exe" -source:package='%RootPath%CCS.zip' -dest:%_Destination% -verb:sync -disableLink:AppPoolExtension -disableLink:ContentExtension -disableLink:CertificateExtension
  146. ) else (
  147. set _MSDeployCommandline="%MSDeployPath%msdeploy.exe" -source:package='%RootPath%CCS.zip' -dest:%_Destination% -verb:sync -disableLink:AppPoolExtension -disableLink:ContentExtension -disableLink:CertificateExtension -setParamFile:"%_DeploySetParametersFile%"
  148. )
  149. if "%_HaveArgMSDeployAdditonalFlags%" == "" (
  150. goto :MSDeployWithOutArgMsDeployAdditionalFlag
  151. )
  152. goto :MSDeployWithArgMsDeployAdditionalFlag
  153. goto :eof
  154. @rem ---------------------------------------------------------------------------------
  155. @rem MSDeployWithArgMsDeployAdditionalFlag
  156. @rem ---------------------------------------------------------------------------------
  157. :MSDeployWithArgMsDeployAdditionalFlag
  158. echo. %_MSDeployCommandline% %_MsDeployAdditionalFlags% %_ArgMsDeployAdditionalFlags:&=^&%
  159. %_MSDeployCommandline% %_MsDeployAdditionalFlags% %_ArgMsDeployAdditionalFlags:&=^&%
  160. IF %ERRORLEVEL% NEQ 0 (
  161. exit 1
  162. )
  163. goto :eof
  164. @rem ---------------------------------------------------------------------------------
  165. @rem MSDeployWithOutArgMsDeployAdditionalFlag
  166. @rem ---------------------------------------------------------------------------------
  167. :MSDeployWithOutArgMsDeployAdditionalFlag
  168. echo. %_MSDeployCommandline% %_MsDeployAdditionalFlags%
  169. %_MSDeployCommandline% %_MsDeployAdditionalFlags%
  170. IF %ERRORLEVEL% NEQ 0 (
  171. exit 1
  172. )
  173. goto :eof
  174. @rem ---------------------------------------------------------------------------------
  175. @rem Find and set IISExpress argument.
  176. @rem ---------------------------------------------------------------------------------
  177. :SetIISExpressArguments
  178. if "%IISExpressPath%" == "" (
  179. for /F "usebackq tokens=1,2,*" %%h in (`reg query "HKLM\SOFTWARE\Microsoft\IISExpress" /s ^| findstr -i "InstallPath"`) do (
  180. if /I "%%h" == "InstallPath" (
  181. if /I "%%i" == "REG_SZ" (
  182. if not "%%j" == "" (
  183. if "%%~dpj" == "%%j" (
  184. set IISExpressPath=%%j
  185. ))))))
  186. if "%IISExpressPath%" == "" (
  187. for /F "usebackq tokens=1,2,*" %%h in (`reg query "HKLM\SOFTWARE\Wow6432Node\Microsoft\IISExpress" /s ^| findstr -i "InstallPath"`) do (
  188. if /I "%%h" == "InstallPath" (
  189. if /I "%%i" == "REG_SZ" (
  190. if not "%%j" == "" (
  191. if "%%~dpj" == "%%j" (
  192. set IISExpressPath=%%j
  193. ))))))
  194. if "%PersonalDocumentFolder%" == "" (
  195. for /F "usebackq tokens=2*" %%i in (`reg query "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" /v Personal`) do (
  196. set PersonalDocumentFolder=%%j
  197. ))
  198. if "%IISExpressManifest%" == "" (
  199. for /F "usebackq tokens=1,2,*" %%h in (`reg query "HKLM\SOFTWARE\Microsoft\IISExpress" /s ^| findstr -i "Manifest"`) do (
  200. if /I "%%h" == "Manifest" (
  201. if /I "%%i" == "REG_SZ" (
  202. if not "%%j" == "" (
  203. set IISExpressManifest=%%j
  204. )))))
  205. if "%IISExpressManifest%" == "" (
  206. for /F "usebackq tokens=1,2,*" %%h in (`reg query "HKLM\SOFTWARE\Wow6432Node\Microsoft\IISExpress" /s ^| findstr -i "Manifest"`) do (
  207. if /I "%%h" == "Manifest" (
  208. if /I "%%i" == "REG_SZ" (
  209. if not "%%j" == "" (
  210. set IISExpressManifest=%%j
  211. )))))
  212. set IISExpressUserProfileDirectory="%PersonalDocumentFolder%\IISExpress\config"
  213. @rem ---------------------------------------------
  214. @rem ---------------------------------------------
  215. goto :eof
  216. @rem ---------------------------------------------------------------------------------
  217. @rem CheckParameterFile -- check if the package's setparamters.xml exists or not
  218. @rem ---------------------------------------------------------------------------------
  219. :CheckParameterFile
  220. if exist "%_DeploySetParametersFile%" (
  221. echo SetParameters from:
  222. echo "%_DeploySetParametersFile%"
  223. echo You can change IIS Application Name, Physical path, connectionString
  224. echo or other deploy parameters in the above file.
  225. ) else (
  226. echo SetParamterFiles does not exist in package location.
  227. echo Use package embedded defaultValue to deploy.
  228. )
  229. echo -------------------------------------------------------
  230. goto :eof
  231. @rem ---------------------------------------------------------------------------------
  232. @rem Usage
  233. @rem ---------------------------------------------------------------------------------
  234. :usage
  235. echo =========================================================
  236. if not exist "%RootPath%CCS.deploy-readme.txt" (
  237. echo Usage:%~nx0 [/T^|/Y] [/M:ComputerName] [/U:userName] [/P:password] [/G:tempAgent] [additional msdeploy flags ...]
  238. echo Required flags:
  239. echo /T Calls msdeploy.exe with the "-whatif" flag, which simulates deployment.
  240. echo /Y Calls msdeploy.exe without the "-whatif" flag, which deploys the package to the current machine or destination server
  241. echo Optional flags:
  242. echo. By Default, this script deploy to the current machine where this script is invoked which will use current user credential without tempAgent.
  243. echo. Only pass these arguments when in advance scenario.
  244. echo /M: Msdeploy destination name of remote computer or proxy-URL. Default is local.
  245. echo /U: Msdeploy destination user name.
  246. echo /P: Msdeploy destination password.
  247. echo /G: Msdeploy destination tempAgent. True or False. Default is false.
  248. echo /A: specifies the type of authentication to be used. The possible values are NTLM and Basic. If the wmsvc provider setting is specified, the default authentication type is Basic
  249. otherwise, the default authentication type is NTLM.
  250. echo /L: Deploy to Local IISExpress User Instance.
  251. echo.[additional msdeploy flags]: note: " is required for passing = through command line.
  252. echo "-skip:objectName=setAcl" "-skip:objectName=dbFullSql"
  253. echo.Alternative environment variable _MsDeployAdditionalFlags is also honored.
  254. echo.
  255. echo. Please make sure MSDeploy is installed in the box https://go.microsoft.com/?linkid=9278654
  256. echo.
  257. echo In addition, you can change IIS Application Name, Physical path,
  258. echo connectionString and other deploy parameters in the following file:
  259. echo "%_DeploySetParametersFile%"
  260. echo.
  261. echo For more information about this batch file, visit https://go.microsoft.com/fwlink/?LinkID=183544
  262. ) else (
  263. start notepad "%RootPath%CCS.deploy-readme.txt"
  264. )
  265. echo =========================================================
  266. goto :eof