C# 使用WPF ClickOnce手动检查更新
我不想使用ClickOnce的默认行为,它显示一个对话框窗口,检查更新,我想手动检查更新 在互联网上搜索后,我发现:C# 使用WPF ClickOnce手动检查更新,c#,wpf,clickonce,C#,Wpf,Clickonce,我不想使用ClickOnce的默认行为,它显示一个对话框窗口,检查更新,我想手动检查更新 在互联网上搜索后,我发现: try { var deploy = ApplicationDeployment.CurrentDeployment; if (deploy.CheckForUpdate()) MessageBox.Show("There is a new update");
try
{
var deploy = ApplicationDeployment.CurrentDeployment;
if (deploy.CheckForUpdate())
MessageBox.Show("There is a new update");
else
MessageBox.Show("You using the latest version");
}
catch (Exception e2)
{
MessageBox.Show(e2.ToString());
}
当我安装应用程序并希望检查更新时,我收到错误:
system.deployment.application.trustnotgrantedexception:用户拒绝向应用程序授予所需的权限
你能帮忙吗
提前感谢。右键单击您的项目。选择属性。然后转到“发布”选项卡。单击更新。然后取消选中“应用程序应检查更新” 我不确定你为什么会犯这样的错误,但我也在使用同样的方法。手动检查更新。但我的应用程序部署在服务器上。我有一个计时器,每15分钟检查一次新的更新 我是这样做的
private void InstallUpdateSyncWithInfo()
{
if (!isNewUpdateMessageShown)
{
try
{
if (ApplicationDeployment.IsNetworkDeployed)
{
ApplicationDeployment ad = ApplicationDeployment.CurrentDeployment;
ad.UpdateCompleted += new AsyncCompletedEventHandler(ad_UpdateCompleted);
//ad_UpdateCompleted is a private method which handles what happens after the update is done
UpdateCheckInfo info = ad.CheckForDetailedUpdate();
if (info.UpdateAvailable)
{
//You can create a dialog or message that prompts the user that there's an update. Make sure the user knows that your are updating the application.
ad.UpdateAsync();//Updates the application asynchronously
}
}
}
catch (Exception ex)
{
ex.Log();
}
}
}
void ad_UpdateCompleted(object sender, AsyncCompletedEventArgs e)
{
//Do something after the update. Maybe restart the application in order for the update to take effect.
}
编辑
我已经更新了我的答案。您可以复制和粘贴此应用程序,并根据您的应用程序需要进行调整
在我之前的回答中,我打开了一个新窗口,告诉用户有更新,然后让用户选择是否要更新应用程序。.Log()、ad\u UpdateCompleted、NewUpdateWindow()、EnableDWMDropShadow、ShowNotifyBaloon、appUpdateTimer未声明。我应该使用什么作为参考?ue能给我一个小的测试应用吗?我们正在使用一些代码,这些代码实际上与上面的ClickOnce VSTO Outlook插件相同。不幸的是,我们得到了一个
TrustNotGrantedException
,表明用户拒绝授予权限,但实际上从来没有任何类型的提示。有什么建议@ljpv14或@abdulsalam elsharif?@TroyAlford我不确定你是否解决了问题。如果没有,请尝试查看@ljpv14-非常感谢!这个链接帮助我们找到了正确的搜索词,我们完全解决了这个问题。你太棒了。:)