为了使你的客户端软件能够能过这种方法升级,你需要把可能会发生变化的Form、算法、业务逻辑等做在dll里面。而实际上,我通常把除了系统的第一个Form以外的所有东西,全部做成dll,谁知道哪些东西可能会变呢?而且系统的第一个Form我通常都做得特别简单,一般仅仅是个欢迎页面,没有变化的需要。
先大概说一下使用SmartAssembly你需要做些什么。首先你需要一台服务器,所有的客户端都能够连接到这台服务器。然后你需要在这台服务器上运行IIS,并建立一个虚拟目录。最后,当某一Dll有新版本时,你只要把它拷贝到这台服务器上的那个目录下即可。因为用户每一次运行客户端程序时,它都会自动到服务器上的虚拟目录中搜索,发现新版本的Dll,会自动下载并替换掉旧版本的Dll。
服务器的IP和所有Dll的名称都在配置文件里面指定,非常简单易懂。而且整个过程,你只需要增加一条额外的代码。
需要加入的一行代码是:
在Main函数中的Application.Run语句前加入如下代码:
ConfigurationSettings.GetConfigLightning.SmartAssemblyConfig.SectionName);
Application.Run();
配置文件如下:
<configuration>
<configSections>
<section name="smartAssemblyConfiguration" type="Lightning.SmartAssemblyConfig, SmartAssembly"/>
</configSections>
<smartAssemblyConfiguration>
<cacheDirectory path="%ComAppData%/Assembly/Origin" type="KeepAllVersions" packageFilePath="%ComAppData%/Assembly/ZipFiles" />
<netSetting agentName="Smart Assemlbly Manager" bufferSize="8182" timeout="-1" rollBack="1024" proxyMode="">
<proxy address="" port="" bypassLocal="" bypassAddresses="" />
</netSetting>
<loadLogic notCheckRemoteWhileMatched="true"
downloadNewerOnly="true"
tryLatestVersionWhileNotMatch="true"
smartMatch="true"
loadSymbols="true"
loadMethod="ShadowCopy"
identifiedByName="true"
workOffline="false"
baseHref="http://127.0.0.1/Assembly/"
defaultZipFile="old.zip" />
<dependentAssembly>
<assemblyIdentity name="SecondForm" publicKeyToken="" culture="" />
<codeBase version="1.1.0.0" href="SecondForm.dll"/>
</dependentAssembly>
</smartAssemblyConfiguration>
</configuration>