Squirrel.Windows UpdateManager.GitHubUpdateManager 需要帮助

Chr*_*ley 4 c# git github squirrel.windows

我正在尝试将 Squirrel.Windows 与我的应用程序一起使用,以从它的 GitHub 存储库安装和自动更新。按照以下示例进行操作

https://github.com/Squirrel/Squirrel.Windows/blob/master/docs/getting-started/1-integrating.md

我能够成功完成所有步骤。我测试了安装,应用程序打开没有问题。我更新并“释放”它,本地安装的应用程序按预期更新。

因此,如果我从本地目录执行此操作,我知道 Squirrel 可以正常工作,但是,我需要从 GitHub 执行此操作。我正在按照这里的说明进行操作

从那以后,我将 App.xaml.cs 中的代码更新为以下内容

public partial class App : Application
{
    protected override async void OnStartup(StartupEventArgs e)
    {
        base.OnStartup(e);
        MessageBox.Show(typeof(App).Assembly.GetName().Version.ToString());

        //  Check for application updates
        using (var mgr = UpdateManager.GitHubUpdateManager("https://github.com/Dartvalince/DiscerningEye"))
        {
            await mgr.Result.UpdateApp();
        }
    }
Run Code Online (Sandbox Code Playgroud)

接下来,我将执行与之前相同的过程,创建 nupkg,并使用 Squirrel 执行 releasify 命令。这里没有问题,很好。

做完这一切之后,我执行 git commit 和 git push 到 GitHub 的源代码。GitHub 上的所有内容都更新为最新的提交。这里很好

接下来,在 GitHub 页面上,我创建了一个新版本。用于发布的标签与创建的 .nupkg 中使用的程序集版本相同。对于要附加到发布的文件,我从Release通过 Squirrel 创建的文件夹中拖放所有文件。

好的,现在一切都在 GitHub 上。然后我开始测试它以确保用户下载所有文件,然后运行 ​​Setup.exe,它会正确安装并打开。当我这样做时,我将每个文件下载到桌面上的一个文件夹中,然后单击 Setup.exe。当我这样做时,我MessageBox.Show(typeof(App).Assembly.GetName().Version.ToString());从应用程序中得到预期的MessageBox 弹出窗口,显示正确的程序集版本号,但没有。就像在这一点上,它卡在代码的更新部分,永远不会过去。我可以让它坐在那里过夜,什么也没有。我什至可以在任务管理器的内存中看到正在运行的进程,所以我知道它没有出错并关闭,但它处于 0% CPU 使用率和 0% 网络使用率。

任何帮助将不胜感激。

Chr*_*ley 6

我想通了这一点,并想为其他可能达到这一点并遇到相同问题的人发布答案。这都是用户错误。

首先,UpdateManagerApp.xaml.cs 的 OnStartup方法内部会导致代码执行停止,await直到更新完成。我将更新检查移至MainWindowViewModel.

从那里,我将更新代码包装在 try/catch 中,并使用 MessageBox 来显示异常消息。它是“找不到资源:错误 404”
我仔细检查了我用于GitHubManager源的 URL ,它是存储库页面的正确地址。
但是,问题出/在 URL 的末尾。我把它从

https://github.com/dartvalince/DiscerningEye/

https://github.com/dartvalince/DiscerningEye

并测试了所有内容,现在可以正常工作了。这是里面的CheckForUpdate功能MainWindowViewModel

private async void CheckForUpdate()
{
    try
    {
        using (var mgr = await UpdateManager.GitHubUpdateManager("https://github.com/dartvalince/DiscerningEye"))
        {
            updateManager = mgr;
            var release = await mgr.UpdateApp();
        }
    }
    catch (Exception ex)
    {
        string message = ex.Message + Environment.NewLine;
        if (ex.InnerException != null)
            message += ex.InnerException.Message;
        MessageBox.Show(message);
    }
}
Run Code Online (Sandbox Code Playgroud)