如何使用ClickOnce部署调试应用程序?

如何使用ClickOnce部署调试应用程序?

问题描述:

我正在开发一个已实施ClickOnce部署的应用程序。当我要检查更新版本程序化的可用性(使用C#)时,它会给我一个例外,比如没有安装应用程序吗?



还有一点 - 在调试时ApplicationDeplyment.IsNetworkDeployed的值始终为false - 不知道为什么??



请建议任何方法来处理此问题。

I am working on an application having ClickOnce Deployment implemented. When I am going to check the availability of newer version programmatic-ally (using C#) it gives me exception like Application not installed?

One more point - while debugging the value of ApplicationDeplyment.IsNetworkDeployed always remains false - not sure why??

Please suggest any way to handle this.

您正在获得未安装应用程序的异常,因为它将检查该应用程序是否已安装在本地计算机上...如果未安装,则可能会导致问题。



并且用于解决与ApplicationDeployment.IsNetworkDeployed相关的问题仍然是错误的,因为在您的发布状态中,您可能未在应用程序安装的计算机上部署网络位置或应用的网络位置。





我也遇到了同样的问题,没有办法调试..所以你可能做的就是你可以在您的网络中的某个位置部署此应用程序(创建网络位置FTP目录),现在尝试从本地计算机访问它并安装应用程序实例,然后您可能会检查您的功能。没有其他方法,您可以做什么最好的检查在不同阶段控制流和值你可以使用活动记录到某个文件,然后获得实现的确切想法,如果在更新过程中发生任何错误,也会得到错误(其他选择是你可以在更新阶段弹出带有值的Messagebox )





请尽量避免在应用程序启动时使用任何应用程序窗口,因为它可能会给您带来问题..







http://msdn.microsoft.com/en-us/library/ms228671(v=vs.80).ASPX [ ^ ]







请查看我的工作代码为下面。实际运行正常,我从MSDN复制了这段代码,但目前还不知道确切的链接(以下代码示例适用于WPF应用程序)。







You are getting exception that application not installed because it will going to check that application is installed on local machine or not ... if not installed then it might get you issue.

And for resolving issue related to ApplicationDeployment.IsNetworkDeployed remains false because in your publish status you might not deployed on network location or applied network location might not be available from application installed machine.


I had also came with same problem and there is no way to debug it .. so what you might do is you can deploy this application somewhere in your network (Make Network location FTP directory) and now try to access it from local machine and Install application Instance and then you Might check your functionality.There is no other way and what best probably you can do for checking control flow and values at different stage you can use logging of activity into some file and then get the exact idea of implementation and also got the error if any occurs during that updation (Other alternative is that you can popup a Messagebox with values during updation stage)


Please Try to avoid use of any application window usage on application startup as it might cause a problem for you ..



http://msdn.microsoft.com/en-us/library/ms228671(v=vs.80).ASPX[^]



Please find my Working code as below.Which is running fine actually and i had copied this code from MSDN but currently dont know exact link(Below Code Sample is for WPF Application).



protected override void OnStartup(StartupEventArgs e)
        {
            Application.Current.DispatcherUnhandledException += Current_DispatcherUnhandledException;
            InstallUpdateSyncWithInfo();
            base.OnStartup(e);
        }
















  private void InstallUpdateSyncWithInfo()
        {
            UpdateCheckInfo info = null;
            
            if (ApplicationDeployment.IsNetworkDeployed)
            {
                ApplicationDeployment ad = ApplicationDeployment.CurrentDeployment;
                try
                {
                    //here as parameter we had provided false
                    //because every time starts up application it will check for updates
                    //and will not store the previous check result into memory.
                    info = ad.CheckForDetailedUpdate(false);
                }
                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)
                    {
                        MessageBoxResult dr = MessageBox.Show("An update is available. Would you like to update the application now?", "EasyLink - Update Available", MessageBoxButton.OKCancel);
                        if (!(MessageBoxResult.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", MessageBoxButton.OK,
                            MessageBoxImage.Information);
                    }

                    if (doUpdate)
                    {
                        try
                        {
                            MessageBox.Show("The application will update in background. Please click on OK and wait for a moment...", "Background Update");
                            ad.Update();
                            MessageBox.Show("The application has been upgraded to the Newer Version (v" + ad.UpdatedVersion.ToString() + "). Please restart the application to run the New Version.", "Update Successful");
                            Application.Current.Shutdown();
                        }
                        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;
                        }
                    }
                }
}
        }