Обновления приложений не инициируются - PullRequest
0 голосов
/ 24 января 2019

У меня есть приложение C # WinForms, которое инициализируется на панели задач при запуске с помощью ярлыка в папке запуска пользователя:

private void checkBox1_CheckedChanged(object sender, EventArgs e)
    {
        string startupFolder = Environment.GetFolderPath(Environment.SpecialFolder.Startup);
        string shortcutAddress = startupFolder + @"\NotifyNinja.lnk";
        if (checkBox1.Checked)
        {
            if (!io.File.Exists(shortcutAddress))
            {
                WshShell shell = new WshShell();
                IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(shortcutAddress);
                shortcut.Description = "A startup shortcut. If you delete this shortcut from your computer, Notify.exe will not launch on Windows Startup"; // set the description of the shortcut
                shortcut.WorkingDirectory = Application.StartupPath; /* working directory */
                shortcut.TargetPath = Application.ExecutablePath; /* path of the executable */
                shortcut.Save(); // save the shortcut 
            }
            else
            {
                io.File.Delete(shortcutAddress);
                WshShell shell = new WshShell();
                IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(shortcutAddress);
                shortcut.Description = "A startup shortcut. If you delete this shortcut from your computer, Notify.exe will not launch on Windows Startup"; // set the description of the shortcut
                shortcut.WorkingDirectory = Application.StartupPath; /* working directory */
                shortcut.TargetPath = Application.ExecutablePath; /* path of the executable */
                shortcut.Save(); // save the shortcut 
            }
        }
        else
        {
            if (io.File.Exists(shortcutAddress))
            {
                io.File.Delete(shortcutAddress);
            }
        }
    }

Это прекрасно работает, но я сделал несколько обновлений для своего приложения с момента его первой публикации, и мои пользователи, похоже, их не получают. Мои обновления установлены на:

  1. Проверка после начала применения
  2. Каждые 7 дней
  3. Не требуется минимальная версия

После дальнейшего тестирования кажется, что если я уберу ярлык запуска, закрою программу и снова открою ее, обновления вступят в силу.

Есть мысли о том, как я могу вызвать обновления для этой автозапускающейся программы?

1 Ответ

0 голосов
/ 30 января 2019

Похоже, что нет подходящего метода для запуска обновлений clickonce при автоматическом запуске приложения с Windows, поэтому мне пришлось вызывать обновления программно:

UpdateCheckInfo info = null;
        if (Directory.Exists(@"F:\..."))
        {
            if (ApplicationDeployment.IsNetworkDeployed)
            {
                ApplicationDeployment ad = ApplicationDeployment.CurrentDeployment;

                try
                {
                    info = ad.CheckForDetailedUpdate();

                }
                catch { }
                if (info.UpdateAvailable)
                {
                    try
                    {
                        ad.Update();
                        Application.Restart();
                    }
                    catch { }
                }
            }
        }
...