由Wix Sharp创建自动更新

时间:2018-06-18 13:57:01

标签: c# wix windows-installer auto-update wixsharp

我使用Wix Sharp创建了一个安装程序。有时应用程序必须更新,对我来说找到方法是很重要的。我认为最好的方法是再创建一个app" App updater",它将检查应用程序的版本,如果有新版本,它将下载并安装它。如何使用Wix Sharp创建更新程序.msi?我必须在哪里上传我的.msi更新程序才能通过"应用程序更新程序"?这是代码:

    static void Main()
    {


        var project = new ManagedProject("MyProduct",
                         new Dir(@"%ProgramFiles%\My Company\My Product",
                             new Files(@"C:\Users\1\source\repos\ParentControl\ParentsControl\*.*")));

        project.GUID = new Guid("6fe30b47-2577-43ad-9095-1861ba25889b");

        project.ManagedUI = ManagedUI.Empty;    //no standard UI dialogs
        project.ManagedUI = ManagedUI.Default;  //all standard UI dialogs

        //custom set of standard UI dialogs
        project.ManagedUI = new ManagedUI();

        project.ManagedUI.InstallDialogs.Add(Dialogs.Welcome)
                                        .Add(Dialogs.Licence)
                                        .Add(Dialogs.SetupType)
                                        .Add(Dialogs.Features)
                                        .Add(Dialogs.InstallDir)
                                        .Add(Dialogs.Progress)
                                        .Add(Dialogs.Exit);

        project.ManagedUI.ModifyDialogs.Add(Dialogs.MaintenanceType)
                                       .Add(Dialogs.Features)
                                       .Add(Dialogs.Progress)
                                       .Add(Dialogs.Exit);

        project.Load += Msi_Load;
        project.BeforeInstall += Msi_BeforeInstall;
        project.AfterInstall += Msi_AfterInstall;

        //project.SourceBaseDir = "<input dir path>";
        //project.OutDir = "<output dir path>";

        project.BuildMsi();
    }

    static void Msi_Load(SetupEventArgs e)
    {
        if (e.IsUninstalling)
        {
            var w = new Ask();
            if(w.ShowDialog()!=DialogResult.Yes)
            {
                MessageBox.Show("Bad password!");
                e.Result = ActionResult.SkipRemainingActions;
            }

        }
        if (!e.IsUISupressed && !e.IsUninstalling)
            MessageBox.Show(e.ToString(), "Load");

    }

    static void Msi_BeforeInstall(SetupEventArgs e)
    {
        if (!e.IsUISupressed && !e.IsUninstalling)
            MessageBox.Show(e.ToString(), "BeforeInstall");
    }

    static void Msi_AfterInstall(SetupEventArgs e)
    {
        if (!e.IsUISupressed && !e.IsUninstalling)
            MessageBox.Show(e.ToString(), "AfterExecute");

    }

1 个答案:

答案 0 :(得分:0)

您是否考虑过将更新添加到您的应用? wyupdate https://wyday.com/wyupdate/可以检测更新,下载并重新启动您的应用。