How to restart WPF application after it has been updated using click-once, i need to start the new version!
Using what Michael provided:
String ApplicationEntryPoint = ApplicationDeployment.CurrentDeployment.UpdatedApplicationFullName;
Process.Start(ApplicationEntryPoint);
Does indeed have the problem of browsers not handling it correctly. For instance Edge would leave a blank browser page after opening your app. Because ApplicationDeployment.CurrentDeployment.UpdatedApplicationFullName refers to a long http url address, there is also the theoretical chance that your Internet drops out the split second after the download finishes and thus your app will not get restarted (cannot access the url).
I went for this instead:
... Update()
if (System.IO.File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.StartMenu) + "\\Programs\\MyCompany\\MyApp.appref-ms"))
{
System.Diagnostics.Process.Start(Environment.GetFolderPath(Environment.SpecialFolder.StartMenu) + "\\Programs\\MyCompany\\MyApp.appref-ms");
}
else if (System.IO.File.Exists(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\MyApp.appref-ms"))
{
System.Diagnostics.Process.Start(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\MyApp.appref-ms");
}
else throw new InvalidOperationException("Cannot restart the application, because StartMenu and Desktop shortcuts are missing!");
... shut down application (this.Close() etc.)
This does of course assume, that you specified your ClickOnce deployment to create shortcuts and that no one has deleted them. But the chance of that is pretty low. (The user probably couldn't execute your app without those shortcuts, because ClickOnce deploys the .exe to a very buried location)
If you really-really wanted to, you could in the final else statement, instead of throwing an exception, create an appref-ms file (google will help) in the temp directory and execute that.