How to Publish an application in Visual Studio
By Tan Lee Published on May 30, 2017 5.81K
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
Structured Data using FoxLearn.JsonLd
Jun 20, 2025
Implement security headers for an ASP.NET Core
Jun 24, 2025
Modernize Material UI Admin Dashboard Template
Nov 19, 2024
SB Admin Template
Nov 14, 2024
RuangAdmin Template
Nov 13, 2024