ClickOnce更新,控制版本跳转

发布于 2025-01-08 14:09:21 字数 530 浏览 2 评论 0原文

我们有一个 ClickOnce 部署的应用程序。我们希望确保安装每次只更新 1 个版本跳转。 (也欢迎其他最佳实践解决方案)。

假设用户安装了 1.16 版本,同时有 2 个新版本,因此服务器上的版本现在是 1.18。我们希望确保下次应用程序更新时,它首先从 1.16 更新到 1.17。然后下次更新时,它会从 1.17 更新到 1.18 等。即,它不会直接从 1.16 更新到 1.18。

为什么,你可能会问。这与我们的应用程序有一个本地(SQL EXPRESS)数据库这一事实有关。我们有一个自定义更新类,该类在应用程序启动时被调用。它检测是否发生了 CO 更新,如果发生了,它会使用可能已进行的任何架构更改来更新本地数据库。即,CO 更新首先提供执行 scehma 更改所需的文件,然后自定义更新类执行实际的数据库修改。当跳转超过 1 个版本时,这是一个问题,因为在此示例中,数据库更改脚本从 v.16 到 v.17 将永远不会被应用。

我们的第一个方法是菊花链 CO 更新文件夹。即v.16从​​1.17更新,1.17从1.18更新,但这似乎并不能解决问题。

有什么想法吗?

We have a ClickOnce deployed application. We would like make sure that the installations only update 1 version jump eacn time. (Other best practice solutions are welcome as well).

Say for example a user has version 1.16 installed, in the mean time there has been 2 new releases so the version on the server is now 1.18. We would like to ensure that the next time the application updates, it updates first from 1.16 to 1.17. Then the next time it updates, it updates from 1.17 to 1.18 etc. I.e. it does not update directly from 1.16 to 1.18.

Why, you might ask. Well it relates to the fact that our application has a local (SQL EXPRESS) database. We have a custom update class which is invoked when the application starts up. It detects if a CO update has occured, if so it updates the local db with any schema changes that may have been made. I.e. the CO update first delivers the files necessary to perform the scehma changes, and then the custom update class performs the actual db modification. This is a problem when jumping more than 1 version since in this example the db changes script from v.16 to v.17 will never be applied.

Our first approach has been to daisy chain CO update folders. That is v.16 updates from 1.17, 1.17 updates from 1.18, but this does not seem to solve the problem.

Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

儭儭莪哋寶赑 2025-01-15 14:09:21

我有一个强大的 ClickOnce 应用程序,它还在最终用户的 PC 上使用 SQL Server Express。在我们的例子中,本地数据库模式的同步是在我们的 Web 服务器上管理的。

应用程序启动后,将从当前客户端数据库中提取版本信息(如果数据库不存在,则返回版本“0”),然后 Web 服务返回构建本地数据库所需的脚本文件。然后,ClickOnce 应用程序按顺序执行脚本,并且完美地构建数据库架构,无论用户上次启动应用程序是什么时候。

更新本地架构后,用户需要访问的任何数据都会从服务器重新同步。这是因为每次更新数据表时,我都必须删除该表,然后从架构更新脚本中重新创建它们。

如果您不想管理这种类型的复杂服务器/客户端脚本/数据库管理系统,为什么不能将关联的 SQL 脚本与您的应用程序捆绑在一起呢?您可以通过在客户端数据库中定义一个维护当前数据库版本的表来实现此目的。当您的用户下载应用程序的新更新时,请检查数据库的版本,并根据客户端当前的数据库版本,执行您使用应用程序编译的可用脚本或命令。

仅将脚本添加到应用程序的每个后续发布中,切勿删除旧脚本。新的 SQL 脚本应该删除并重新创建任何正在更新的对象。如果您的应用程序在应用程序执行脚本的过程中发生崩溃,这可以为您省去不少麻烦。我经历了惨痛的教训才明白这一点。

我建议创建一个同步机制,其中版本检查从您的服务器进行管理,而不是使用脚本或嵌入 SQL 命令与您的应用程序一起编译。这样,无需发布应用程序即可对数据库进行较小的更改。相信我,您的用户会感谢您,因为他们不必频繁下载应用程序更新。相反,这些类型的更改将是无缝的,并将在幕后自动发生。

I have a robust ClickOnce application that also makes use of SQL Server Express on the end user's PC. In our case, syncing of the local database schema is managed on our web server.

After the application starts, version information is pulled from the current client database (with a version of "0" being returned if the DB doesn't exist) and then a web service returns the necessary script files to build the local database. The ClickOnce application then executes the scripts in sequential order and the database schema is built, perfectly, regardless of when the last time was that the user launched the application.

After the local schema has been updated, any data that the user needs to access is re-synced from the server. This is because each time I update a data table, I have to DROP the table and then recreate them from within my schema update scripts.

If you would rather not manage this type of complex server/client script/db management system, why can't you bundle the associated SQL scripts with your application? You could accomplish this by defining a table within your client DB that maintains the current DB version. When your user downloads a new update to your application, check the version of the DB and, depending on the client's current DB version, execute the available scripts or commands that you've compiled with your application.

Only add scripts to each subsequent publication of your application and never remove old ones. New SQL scripts should DROP and recreate any object that is being updated. This can save you quite a few headaches if your application happens to crash in the middle of a script being executed by your application. I've learned this the hard way.

I would recommend creating a syncing mechanism where version checks are managed from your server, instead of having scripts or having embedded SQL commands compiled with your application. This way, minor changes to the database can be made without having to publish your application. Trust me, your user's will thank you because they won't have to download frequent application updates. Instead, these types of changes will be seamless and will take place automatically behind-the-scenes.

意中人 2025-01-15 14:09:21

我粘贴了一种方法,用于查找程序版本(如果从桌面启动)和更新版本(如果从 ClickOnce 启动)。

    private string GetTheVersion()
    {
        string version = string.Empty;
        Version currentVersion;
        Version updateVersion;
        StringBuilder sb = new StringBuilder();
        if (ApplicationDeployment.IsNetworkDeployed)
        {
                currentVersion = ApplicationDeployment.CurrentDeployment.CurrentVersion;
            updateVersion = ApplicationDeployment.CurrentDeployment.UpdatedVersion;

            sb.AppendLine(string.Format("Current Version: {0}.{1}.{2}.{3}", currentVersion.Major.ToString(), currentVersion.Minor.ToString(), currentVersion.MajorRevision.ToString(), currentVersion.MinorRevision.ToString()));
            sb.AppendLine(string.Format("Updated Version: {0}.{1}.{2}.{3}", updateVersion.Major.ToString(), updateVersion.Minor.ToString(), updateVersion.MajorRevision.ToString(), updateVersion.MinorRevision.ToString()));
            version = sb.ToString();
        }
        else
        {
            currentVersion = Assembly.GetCallingAssembly().GetName().Version;
            version = string.Format("Current Version: {0}.{1}.{2}.{3}", currentVersion.Major.ToString(), currentVersion.Minor.ToString(), currentVersion.MajorRevision.ToString(), currentVersion.MinorRevision.ToString());
        }

        return version;
    }

当然,其中的内容超出了您的需要,但是您可以使用 ApplicationDeployment.CurrentDeployment 类的方法来确定是否执行更新。您可以在命令行参数或 url 查询字符串变量中传递您希望现有应用程序使用的最低版本,具体取决于您的部署方式。

乔伊

I am pasting a method I use to find the version of the program if it is launched from the desktop and the version of the update if it is launched from ClickOnce.

    private string GetTheVersion()
    {
        string version = string.Empty;
        Version currentVersion;
        Version updateVersion;
        StringBuilder sb = new StringBuilder();
        if (ApplicationDeployment.IsNetworkDeployed)
        {
                currentVersion = ApplicationDeployment.CurrentDeployment.CurrentVersion;
            updateVersion = ApplicationDeployment.CurrentDeployment.UpdatedVersion;

            sb.AppendLine(string.Format("Current Version: {0}.{1}.{2}.{3}", currentVersion.Major.ToString(), currentVersion.Minor.ToString(), currentVersion.MajorRevision.ToString(), currentVersion.MinorRevision.ToString()));
            sb.AppendLine(string.Format("Updated Version: {0}.{1}.{2}.{3}", updateVersion.Major.ToString(), updateVersion.Minor.ToString(), updateVersion.MajorRevision.ToString(), updateVersion.MinorRevision.ToString()));
            version = sb.ToString();
        }
        else
        {
            currentVersion = Assembly.GetCallingAssembly().GetName().Version;
            version = string.Format("Current Version: {0}.{1}.{2}.{3}", currentVersion.Major.ToString(), currentVersion.Minor.ToString(), currentVersion.MajorRevision.ToString(), currentVersion.MinorRevision.ToString());
        }

        return version;
    }

There is more there than you need, of course, but you can then use the methods of the ApplicationDeployment.CurrentDeployment class to determine whether or not to perform the update. You could pass the minimum version you want the existing app to be in a command line argument or url querystring variable, depending on how you are deploying.

Joey

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文