【发布时间】:2021-04-01 12:31:48
【问题描述】:
我从 Walkthrough: Creating a Custom Installer for a ClickOnce Application (C#) 和 Walkthrough: Creating a Custom Installer for a ClickOnce Application (VB) 借用了代码,为我们的 ClickOnce 部署创建了我自己的自定义安装程序。
我启动了一个新的 VB.NET 项目用作安装程序,并添加了如下所示的 MyInstaller 类。
看起来代码应该“开箱即用”,但我发现当我调用 GetManifestAsync 时,GetManifestCompleted 事件永远不会触发。
我已尝试将 myApp.application 的有效 URL 以及它在我的服务器上的 UNC 路径名传递给它。我还尝试将 invalid URL 和 invalid UNC 路径名传递给它,以查看是否可以让它引发错误,但它并没有这样做当我打电话给iphm = New InPlaceHostingManager(deploymentUri, False)时。
由于调用是异步的,我正在调用 InstallApplication 方法,然后坐在 Do...Loop 中等待它完成。
对我可能遗漏或做错了什么有什么想法?
这是 MyInstaller 类:
Public Class MyInstaller
Private WithEvents iphm As InPlaceHostingManager = Nothing
Public Event DownloadProgressChanged(ByVal sender As Object, ByVal e As DownloadProgressChangedEventArgs)
Public Property IsComplete As Boolean = False
Public Sub InstallApplication(ByVal deployManifestUriStr As String)
Try
Dim deploymentUri As New Uri(deployManifestUriStr)
iphm = New InPlaceHostingManager(deploymentUri, False)
Catch uriEx As UriFormatException
MessageBox.Show("Cannot install the application: The deployment manifest URL supplied is not a valid URL. Error: " & uriEx.Message)
Return
Catch platformEx As PlatformNotSupportedException
MessageBox.Show("Cannot install the application: This program requires Windows XP or higher. Error: " & platformEx.Message)
Return
Catch argumentEx As ArgumentException
MessageBox.Show("Cannot install the application: The deployment manifest URL supplied is not a valid URL. Error: " & argumentEx.Message)
Return
End Try
iphm.GetManifestAsync()
End Sub
Private Sub iphm_GetManifestCompleted(ByVal sender As Object, ByVal e As GetManifestCompletedEventArgs) Handles iphm.GetManifestCompleted
' Check for an error.
If (e.Error IsNot Nothing) Then
' Cancel download and install.
MessageBox.Show("Could not download manifest. Error: " & e.Error.Message)
Return
End If
' Dim isFullTrust As Boolean = CheckForFullTrust(e.ApplicationManifest)
' Verify this application can be installed.
Try
' the true parameter allows InPlaceHostingManager
' to grant the permissions requested in the application manifest.
iphm.AssertApplicationRequirements(True)
Catch ex As Exception
MessageBox.Show("An error occurred while verifying the application. Error text: " & ex.Message)
Return
End Try
' Use the information from GetManifestCompleted() to confirm
' that the user wants to proceed.
Dim appInfo As String = "Application Name: " & e.ProductName
appInfo &= ControlChars.Lf & "Version: " & e.Version.ToString()
appInfo &= ControlChars.Lf & "Support/Help Requests: "
If Not (e.SupportUri Is Nothing) Then
appInfo &= e.SupportUri.ToString()
Else
appInfo &= "N/A"
End If
appInfo &= ControlChars.Lf & ControlChars.Lf & "Confirmed that this application can run with its requested permissions."
' If isFullTrust Then
' appInfo &= ControlChars.Lf & ControlChars.Lf & _
' "This application requires full trust in order to run."
' End If
appInfo &= ControlChars.Lf & ControlChars.Lf & "Proceed with installation?"
Dim dr As DialogResult = MessageBox.Show(appInfo, "Confirm Application Install", MessageBoxButtons.OKCancel, MessageBoxIcon.Question)
If dr <> System.Windows.Forms.DialogResult.OK Then
Return
End If
' Download the deployment manifest.
' Usually, this shouldn't throw an exception unless
' AssertApplicationRequirements() failed, or you did not call that method
' before calling this one.
Try
iphm.DownloadApplicationAsync()
Catch downloadEx As Exception
MessageBox.Show("Cannot initiate download of application. Error: " & downloadEx.Message)
Return
End Try
End Sub
Private Sub iphm_DownloadProgressChanged(ByVal sender As Object, ByVal e As DownloadProgressChangedEventArgs) Handles iphm.DownloadProgressChanged
' you can show percentage of task completed using e.ProgressPercentage
RaiseEvent DownloadProgressChanged(sender, e)
End Sub
Private Sub iphm_DownloadApplicationCompleted(ByVal sender As Object, ByVal e As DownloadApplicationCompletedEventArgs) Handles iphm.DownloadApplicationCompleted
' Check for an error.
If (e.Error IsNot Nothing) Then
' Cancel download and install.
MessageBox.Show("Could not download and install application. Error: " & e.Error.Message)
Return
End If
' Inform the user that their application is ready for use.
MessageBox.Show("Application installed! You may now run it from the Start menu.")
IsComplete = True
End Sub
结束类
我是这样称呼它的:
Dim installer As New MyInstaller()
installer.InstallApplication("\\myServer\myShare\myApp.application")
'installer.InstallApplication("http://myServer/myShare/myApp.application")
Do
System.Threading.Thread.Sleep(500)
Loop Until installer.IsComplete
MessageBox.Show("Installer object created.")
【问题讨论】: