При попытке обновления файл .application загружается, а не запускается.
Браузер обрабатывает файл .application. как обычную загрузку, а не распознавать его как файл развертывания ClickOnce.
Это препятствует беспрепятственному обновлению приложения по назначению.
Я хочу, чтобы процесс обновления запускал .application напрямую и автоматически перезапускает приложение после применения обновления, не требуя от пользователя перезапуска его вручную.
Вот моя текущая структура развертывания на Bluehost:
Код: Выделить всё
/solutions/
internaltesting.application
mysolutions.version.txt
publish.htm
setup.exe
Application Files/....
Код: Выделить всё
public static Version? CheckForUpdates()
{
try
{
Version currentVersion = GetCurrentAssemblyVersion();
using (WebClient client = new WebClient())
{
client.CachePolicy = new RequestCachePolicy(RequestCacheLevel.NoCacheNoStore);
// Fetch the latest version from the server
string versionString = client.DownloadString(serverUpdateUrl + "mysolutions.version.txt").Trim();
Version latestVersion = Version.Parse(versionString);
Debug.WriteLine($"Current Version: {currentVersion}, Latest Version: {latestVersion}");
// Return the latest version if it's newer than the current version
return latestVersion > currentVersion ? latestVersion : null;
}
}
catch (Exception ex)
{
MessageBox.Show($"Error checking for updates: {ex.Message}", "Update Error", MessageBoxButton.OK, MessageBoxImage.Error);
return null;
}
}
public static Version GetCurrentAssemblyVersion()
{
if (ApplicationDeployment.IsNetworkDeployed)
{
return ApplicationDeployment.CurrentDeployment.CurrentVersion;
}
Assembly assembly = Assembly.GetExecutingAssembly();
FileVersionInfo versionInfo = FileVersionInfo.GetVersionInfo(assembly.Location);
Debug.WriteLine($"Running Assembly Version: {versionInfo.ProductVersion}");
return new Version(versionInfo.ProductVersion);
}
public static void PerformUpdate()
{
try
{
if (ApplicationDeployment.IsNetworkDeployed)
{
ApplicationDeployment deployment = ApplicationDeployment.CurrentDeployment;
if (deployment.CheckForUpdate())
{
deployment.Update();
MessageBox.Show("The application has been updated successfully! Restarting...",
"Update Successful",
MessageBoxButton.OK,
MessageBoxImage.Information);
RestartApplicationInClickOnceContext();
Application.Current.Shutdown();
}
else
{
MessageBox.Show("No updates are available.", "No Updates Available", MessageBoxButton.OK, MessageBoxImage.Information);
}
}
else
{
MessageBox.Show("This application is not network-deployed. Updates are not available.",
"Update Error",
MessageBoxButton.OK,
MessageBoxImage.Warning);
}
}
catch (Exception ex)
{
MessageBox.Show($"Update failed: {ex.Message}", "Update Error", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
private static void RestartApplicationInClickOnceContext()
{
try
{
// Restart the application using the ClickOnce deployment URL
string activationUrl = ApplicationDeployment.CurrentDeployment.UpdateLocation.AbsoluteUri;
Process.Start(new ProcessStartInfo
{
FileName = activationUrl,
UseShellExecute = true
});
}
catch (Exception ex)
{
MessageBox.Show($"Failed to restart the application: {ex.Message}", "Restart Error", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
Когда пользователь запускает обновление, файл .application должен запускаться/устанавливаться автоматически, а не загружаться. >
После установки обновления приложение должно автоматически перезапуститься, не требуя от пользователя его ручного перезапуска.
Подробнее здесь: https://stackoverflow.com/questions/792 ... -of-runnin