How to Publish an application in Visual Studio
By FoxLearn 5/30/2017 6:33:38 AM 5.38K
How to publish a windows forms application in Visual Studio with auto update using c#, create a ClickOnce setup
Step 1: Click New Project, then select Visual C# on the left, then Windows and then select Windows Forms Application. Name your project "AutoUpdate" and then click OK
Step 2: Design a simple form as below
Step 3: Add code to handle button event
private void button1_Click(object sender, EventArgs e) { UpdateCheckInfo info; if (ApplicationDeployment.IsNetworkDeployed) { ApplicationDeployment ad = ApplicationDeployment.CurrentDeployment; try { info = ad.CheckForDetailedUpdate(); } catch (DeploymentDownloadException dde) { MessageBox.Show("The new version of the application can't be downloaded at this time.\n\nPlease check your network connection or try again later. Error: " + dde.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } catch (InvalidDeploymentException ide) { MessageBox.Show("Can't check for a new version of the application. The ClickOnce deployment is corrupt. Please redeploy the application and try again. Error: " + ide.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } catch (InvalidOperationException ioe) { MessageBox.Show("This application can't be updated. It's likely not a ClickOnce application. Error: " + ioe.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (info.UpdateAvailable) { if (MessageBox.Show("A newer version is available. Would you like to update it now ?", "Message", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { try { ad.Update(); Application.Restart(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } else MessageBox.Show("You are running the latest version.", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
VIDEO TUTORIALS
Categories
Popular Posts
11 Things You Didn't Know About Cloudflare
12/19/2024