您的位置:首页 > 其它

通过彻底清理ClickOnce部署的程序,修复ClickOnce自动升级的一些问题

2009-09-28 15:28 417 查看
微软的ClickOnce技术给我们的应用程序部署带来了很大的便捷,但常常会因为用户计算机操作系统,其他软件,更新到一半出错,等一系列因素的影响而无法自动更新.通常会提示"无法启动应用程序。请与程序供应商联系。"

平台版本信息
Windows : 5.1.2600.131072 (Win32NT)
Common Language Runtime : 2.0.50727.832
System.Deployment.dll : 2.0.50727.832 (QFE.050727-8300)
mscorwks.dll : 2.0.50727.832 (QFE.050727-8300)
dfdll.dll : 2.0.50727.42 (RTM.050727-4200)
dfshim.dll : 2.0.50727.42 (RTM.050727-4200)


部署 URL : xxxxx

错误摘要
以下是错误摘要,这些错误的详细信息列在该日志的后面。
* 激活 xxxxx 导致异常。 检测到下列失败消息:
+ 参照的汇编没有安装在系统上。 (异常来自 HRESULT:0x800736B3)

组件存储事务失败摘要
未检测到任何事务错误。

警告
执行此操作的过程中未出现任何警告。

操作进度状态
* [2007-11-5 9:26:31] : 已启动 xxxxx 的激活过程。

错误详细信息
执行此操作期间检测到下列错误。
* [2007-11-5 9:26:34] System.Runtime.InteropServices.COMException
- 参照的汇编没有安装在系统上。 (异常来自 HRESULT:0x800736B3)
- 源: System.Deployment
- 堆栈跟踪:
在 System.Deployment.Internal.Isolation.IStore.GetAssemblyInformation(UInt32 Flags, IDefinitionIdentity DefinitionIdentity, Guid& riid)
在 System.Deployment.Internal.Isolation.Store.GetAssemblyManifest(UInt32 Flags, IDefinitionIdentity DefinitionIdentity)
在 System.Deployment.Application.ComponentStore.GetSubscriptionStateInternal(DefinitionIdentity subId)
在 System.Deployment.Application.SubscriptionStore.GetSubscriptionStateInternal(SubscriptionState subState)
在 System.Deployment.Application.SubscriptionStore.CheckAndReferenceApplication(SubscriptionState subState, DefinitionAppId appId, Int64 transactionId)
在 System.Deployment.Application.DownloadManager.DownloadDeploymentManifestDirectBypass(SubscriptionStore subStore, Uri& sourceUri, TempFile& tempFile, SubscriptionState& subState, IDownloadNotification notification, DownloadOptions options, ServerInformation& serverInformation)
在 System.Deployment.Application.DownloadManager.DownloadDeploymentManifestBypass(SubscriptionStore subStore, Uri& sourceUri, TempFile& tempFile, SubscriptionState& subState, IDownloadNotification notification, DownloadOptions options)
在 System.Deployment.Application.ApplicationActivator.PerformDeploymentActivation(Uri activationUri, Boolean isShortcut)
在 System.Deployment.Application.ApplicationActivator.ActivateDeploymentWorker(Object state)

组件存储事务详细信息
没有可用的事务信息。

以上只是诸多错误中的一种。本人认为,但凡此类错误,一般都是因为某种原因(如更新了一半网络中断)造成的程序文件损坏或者与注册表中的版本不一致所致,可以通过卸载重新安装解决。但往往从控制面板的添加删除程序中不能彻底卸载。因此写了个小程序来清理应用程序部署文件和注册表中的版本信息,代码如下:

using System;
using System.IO;
using Microsoft.Win32;

/*
* 作者Vincent;
* 联系地址:http://free.free-web-hosting.biz/
* 使用之前请先将ClearReg()方法中的YourAppName替换为您的程序集的名称
*/
namespace ClickOnceCleaner
{
internal class Program
{
private static void Main()
{
Console.WriteLine("正在清理ClickOnce残留文件...");
ClearFiles();
Console.WriteLine("正在清理注册表..");
ClearReg();
Console.WriteLine("清理成功,按回车键退出!");
Console.ReadLine();
}

private static void ClearFiles()
{
string fl = string.Format(@"C:/Documents and Settings/{0}/Local Settings/Apps/2.0", Environment.UserName);
if (Directory.Exists(fl))
Directory.Delete(fl, true);
}

private static void ClearReg()
{
RegistryKey depKey = Registry.CurrentUser.OpenSubKey("Software").OpenSubKey("Classes").
OpenSubKey("Software").OpenSubKey("Microsoft").OpenSubKey("Windows").
OpenSubKey("CurrentVersion").OpenSubKey("Deployment").OpenSubKey("SideBySide").
OpenSubKey("2.0");
DeleteKey(depKey,"YourAppName");
}

private static void DeleteKey(RegistryKey key, string appNmae)
{
string[] subNames = key.GetSubKeyNames();
if (subNames == null || subNames.Length == 0)
return;
foreach (string name in subNames)
{
RegistryKey childKey = key.OpenSubKey(name, RegistryKeyPermissionCheck.ReadWriteSubTree);
string[] childKeyNames = childKey.GetSubKeyNames();
if (childKeyNames == null || childKeyNames.Length == 0)
continue;
foreach (string childKeyName in childKeyNames)
if (childKeyName.Contains(appNmae))
childKey.DeleteSubKeyTree(childKeyName);
else
DeleteKey(childKey, appNmae);
}
}
}
}

希望以上代码能够解决您在ClickOnce程序部署中遇到的一部分问题。
代码下载 http://free.free-web-hosting.biz/attachment/ClickOnceCleaner.zip

文章出处:http://www.diybl.com/course/4_webprogram/asp.net/netjs/2007116/84726.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐