【问题标题】:Reliable way to automatically update Click-Once network deployed application自动更新 Click-Once 网络部署应用程序的可靠方法
【发布时间】:2018-09-27 17:46:58
【问题描述】:

我已经为此工作了几个月,但没有真正成功。 我拼凑了来自不同来源的代码,这就是我所拥有的。

有时它按预期工作,有时应用程序只是冻结,有时它更新 4 次。

我有一个 5 分钟的计时器间隔,用于检查更新是否可用,以及是否有更新和重新启动。简单吧?

应用程序是网络部署的,有时用户会让应用程序运行数周而不退出。发布更新后,它们可能会因为新功能或数据库更改而出错。

为什么会有如此不同的结果?

这是表单加载事件...

Me.Timer2.Interval = 300000 Me.Timer2.Start()

这是 Timer_Tick 事件...

 Private Sub Timer2_Tick(sender As Object, e As EventArgs) Handles Timer2.Tick

    If CheckForUpdateDue() Then
        My.Forms.PopupLoading.Show()
        My.Forms.PopupLoading.Label1.Text = "Project is Updating Please Wait..."
        My.Forms.PopupLoading.Refresh()
        Dim ad As ApplicationDeployment = ApplicationDeployment.CurrentDeployment
        ad.Update()
        My.Settings.Save()
        My.Forms.PopupLoading.Close()
        My.Forms.Popup_Restarting.Show()
        Application.Restart()
    End If

End Sub

这里是 CheckForUpdateDue 函数...

 Private Function CheckForUpdateDue() As Boolean
    Dim isUpdateDue As Boolean = False
    If ApplicationDeployment.IsNetworkDeployed Then
        Dim AD As ApplicationDeployment = ApplicationDeployment.CurrentDeployment
        If AD.CheckForUpdate() Then
            isUpdateDue = True
        End If
    End If
    CheckForUpdateDue = isUpdateDue
End Function

Application Settings

Application Update Settings

【问题讨论】:

  • 您能否检查更新,调用一个批处理文件,等待 5 秒后重新启动应用程序,关闭应用程序,然后让 Click-Once 完成工作?
  • 或另一个具有应用程序/数据库版本的表,如果版本错误,则强制应用程序关闭?

标签: vb.net deployment clickonce auto-update intranet


【解决方案1】:

看起来My.Application.Deployment.CheckForUpdate() 是要走的路。它会检查UpdateLocation 以查看是否有可用更新并要求用户下载它,或者您可以使用My.Application.Deployment.CheckForUpdate(true) 强制进行静默更新。

我尝试在调试模式下在我的项目中使用它,它抛出了 InvalidDeploymentException,但我认为它应该可以在具有 Click-Once 部署的生产代码中工作

【讨论】:

  • 要求此代码不在工作时间运行,并且在没有用户参与的情况下运行。于是有了计时器。
  • @JDesigns 对...我试图为您指明正确的方向。我无意为你编写代码。
【解决方案2】:

这就是我最终的结果......

 Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
    Dim ct As Date = DateTime.Now
    If ct.Hour = 22 Then
        Dim info As UpdateCheckInfo = Nothing

        If ApplicationDeployment.IsNetworkDeployed Then
            Dim AD As ApplicationDeployment = ApplicationDeployment.CurrentDeployment

            Try
                info = AD.CheckForDetailedUpdate()
            Catch dde As DeploymentDownloadException
                MessageBox.Show("The new version of the application cannot be downloaded at this time. " & ControlChars.Lf & ControlChars.Lf & "Please check your network connection, or try again later. Error: " + dde.Message)
                Return
            Catch ioe As InvalidOperationException
                MessageBox.Show("This application cannot be updated. It is likely not a ClickOnce application. Error: " & ioe.Message)
                Return
            End Try

            If info.UpdateAvailable Then
                Dim doUpdate As Boolean = True

                If doUpdate Then
                    Try
                        'restart application first
                        Application.Restart()
                        'then do update
                        AD.Update()
                        'when the application is restarted again it will be update
                    Catch dde As DeploymentDownloadException
                        MessageBox.Show("Cannot install the latest version of the application. " & ControlChars.Lf & ControlChars.Lf & "Please check your network connection, or try again later.")
                        Return
                    End Try
                End If
            End If
        End If
    End If

End Sub

取自Microsoft VS Docs 似乎在工作 将拭目以待.....

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-05-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多