Kevin Li

突破.net极限

导航

使用WMI远程部署/更新BizTalk程序集

Posted on 2007-06-12 14:57  Kevin Li  阅读(565)  评论(0编辑  收藏  举报

当BizTalk使用多服务器部署方案时,如果要更新BizTalk Application引用到的程序集,就必须将程序集同时更新到多台服务器的GAC中。如果每次更新以后,都需要手工在多台服务器更新,实在太麻烦。为了偷懒,就想到用WMI在远程服务器上创建进程来更新GAC中的程序集:)

用WMI在远程服务器上创建进程的命令如下:
WMIC /node:server01 /user:mydomain\myusername /password:pass@word1 process call create "C:\gacutil /u myBizAssembly"
WMIC /node:server01 /user:mydomain\myusername /password:pass@word1 process call create "C:\gacutil /i C:\Deploy\myBizAssembly.dll"

接下来要做的就是将程序集,从Build机器copy到deploy服务器上,然后调用gacutil卸载程序集、重新安装程序集和重启BizTalk Host Instances了。把所有的命令都写到一个批处理文件就可以:

@Echo Copy files
Copy C:\Build\myBizAssembly.dll \\Server01\Deploy\myBizAssembly.dll 
Copy C:\Build\myBizAssembly.dll \\Server02\Deploy\myBizAssembly.dll
Copy C:\Build\myBizAssembly.dll \\Server03\Deploy\myBizAssembly.dll

@Echo Install assemblies to GAC
WMIC 
/node:server01 /user:mydomain\myusername /password:pass@word1 process call create "C:\gacutil /u myBizAssembly"
WMIC 
/node:server01 /user:mydomain\myusername /password:pass@word1 process call create "C:\gacutil /i C:\Deploy\myBizAssembly.dll"
WMIC 
/node:server02 /user:mydomain\myusername /password:pass@word1 process call create "C:\gacutil /u myBizAssembly"
WMIC 
/node:server02 /user:mydomain\myusername /password:pass@word1 process call create "C:\gacutil /i C:\Deploy\myBizAssembly.dll"
WMIC 
/node:server03 /user:mydomain\myusername /password:pass@word1 process call create "C:\gacutil /u myBizAssembly"
WMIC 
/node:server03 /user:mydomain\myusername /password:pass@word1 process call create "C:\gacutil /i C:\Deploy\myBizAssembly.dll"

@Echo Restart Host Instances
WMIC 
/node:server01 /user:mydomain\myusername /password:pass@word1 process call create "net stop BTSSvc$BizTalkReceiveHost"
WMIC 
/node:server01 /user:mydomain\myusername /password:pass@word1 process call create "net start BTSSvc$BizTalkReceiveHost"
WMIC 
/node:server02 /user:mydomain\myusername /password:pass@word1 process call create "net stop BTSSvc$BizTalkProcessHost"
WMIC 
/node:server02 /user:mydomain\myusername /password:pass@word1 process call create "net start BTSSvc$BizTalkProcessHost"
WMIC 
/node:server01 /user:mydomain\myusername /password:pass@word1 process call create "net stop BTSSvc$BizTalkSendHost"
WMIC 
/node:server01 /user:mydomain\myusername /password:pass@word1 process call create "net start BTSSvc$BizTalkSendHost"


不过这种方式,只适合不影响到BizTalk的Bindings的时候,比如新的程序集相对原来的程序集,多了一个ReceivePort,这种方式没办法更新BizTalk的Bindings。

这种方式,也适用于daily build後将程序集部署到测试服务器上,只需要加一段自定义任务就可以。

<Target Name="AfterCompile">
        
<Exec Command="&quot;c:\mywmideploy.bat&quot;"/>
</Target>