我在查看ClickOnce如何知道它如何比较文件以及它如何查找这些文件时遇到了问题。我将把我的ClickOnce应用程序连接到服务器,但它是否在内部执行此操作?
答案 0 :(得分:0)
您将在 Publishing ClickOnce Applications (MSDN)中找到所需的一切。
来自 How to: Check for Application Updates Programmatically Using the ClickOnce Deployment API :
- 使用首选命令行或可视化工具创建新的Windows窗体应用程序。
- 创建您希望用户选择以检查更新的任何按钮,菜单项或其他用户界面项。从那个项目 事件处理程序,调用以下方法来检查和安装 更新。
醇>
private void InstallUpdateSyncWithInfo()
{
UpdateCheckInfo info = null;
if (ApplicationDeployment.IsNetworkDeployed)
{
ApplicationDeployment ad = ApplicationDeployment.CurrentDeployment;
try
{
info = ad.CheckForDetailedUpdate();
}
catch (DeploymentDownloadException dde)
{
MessageBox.Show("The new version of the application cannot be downloaded at this time. \n\nPlease check your network connection, or try again later. Error: " + dde.Message);
return;
}
catch (InvalidDeploymentException ide)
{
MessageBox.Show("Cannot check for a new version of the application. The ClickOnce deployment is corrupt. Please redeploy the application and try again. Error: " + ide.Message);
return;
}
catch (InvalidOperationException ioe)
{
MessageBox.Show("This application cannot be updated. It is likely not a ClickOnce application. Error: " + ioe.Message);
return;
}
if (info.UpdateAvailable)
{
Boolean doUpdate = true;
if (!info.IsUpdateRequired)
{
DialogResult dr = MessageBox.Show("An update is available. Would you like to update the application now?", "Update Available", MessageBoxButtons.OKCancel);
if (!(DialogResult.OK == dr))
{
doUpdate = false;
}
}
else
{
// Display a message that the app MUST reboot. Display the minimum required version.
MessageBox.Show("This application has detected a mandatory update from your current " +
"version to version " + info.MinimumRequiredVersion.ToString() +
". The application will now install the update and restart.",
"Update Available", MessageBoxButtons.OK,
MessageBoxIcon.Information);
}
if (doUpdate)
{
try
{
ad.Update();
MessageBox.Show("The application has been upgraded, and will now restart.");
Application.Restart();
}
catch (DeploymentDownloadException dde)
{
MessageBox.Show("Cannot install the latest version of the application. \n\nPlease check your network connection, or try again later. Error: " + dde);
return;
}
}
}
}
}
答案 1 :(得分:0)
如果您不想进行程序化更新,请在“更新”对话框中设置“运行前检查更新”(单击“发布”屏幕上的“更新”)。然后,当您发布新版本时,它将与原始部署位于相同的文件夹中。当用户运行应用程序时,它将检查是否有更新,并询问他是否要安装它。此时,用户可以跳过它,或接受更新。
如果您使最低版本(在更新对话框中)等于您正在部署的版本,它将不会询问他,它只会更新应用程序。
如果他跳过更新,他将在几周内再也看不到它,如果有的话。微软说2个星期,但我不相信它会再次出现,所以他可能要等到NEXT更新或者手动安装新的。