【问题标题】:How can I check github releases in c#?如何在 c# 中检查 github 版本?
【发布时间】:2014-10-29 23:35:27
【问题描述】:

类似的东西。

void UpdateCheck()
{
    if (GithubApi.GetCurrentRelease().Version > CurrentVersion)
}

我该怎么做?

我找到了一些 API,https://github.com/octokit/octokit.net

但是我找不到这个功能。

【问题讨论】:

    标签: c# api github release octokit.net


    【解决方案1】:

    使用 Octokit.net,您应该能够开始使用文档中的 this example

    全部获取

    要检索存储库的所有版本:

    var releases = client.Release.GetAll("octokit", "octokit.net");
    var latest = releases[0];
    Console.WriteLine(
        "The latest release is tagged at {0} and is named {1}", 
        latest.TagName, 
        latest.Name); 
    

    或者,您也可以直接use the API

    列出存储库的版本

    每个人都可以获取有关已发布版本的信息。只有具有推送访问权限的用户才能收到草稿版本的列表。

    GET /repos/:owner/:repo/releases
    

    【讨论】:

      【解决方案2】:

      我用 octokit.net 的最新更改更新了 Chris 代码,因为 Octokit 的文档有点不清楚。如果没有 await/async 关键字,代码将无法工作。

      using System;
      using Octokit;
      
      private async System.Threading.Tasks.Task CheckGitHubNewerVersion()
      {
          //Get all releases from GitHub
          //Source: https://octokitnet.readthedocs.io/en/latest/getting-started/
          GitHubClient client = new GitHubClient(new ProductHeaderValue("SomeName"));
          IReadOnlyList<Release> releases = await client.Repository.Release.GetAll("Username", "Repository");
          
          //Setup the versions
          Version latestGitHubVersion = new Version(releases[0].TagName);
          Version localVersion = new Version("X.X.X"); //Replace this with your local version. 
                                                       //Only tested with numeric values.
          
          //Compare the Versions
          //Source: https://stackoverflow.com/questions/7568147/compare-version-numbers-without-using-split-function
          int versionComparison = localVersion.CompareTo(latestGitHubVersion);
          if (versionComparison < 0)
          {
              //The version on GitHub is more up to date than this local release.
          }
          else if (versionComparison > 0)
          {
              //This local version is greater than the release version on GitHub.
          }
          else
          {
              //This local Version and the Version on GitHub are equal.
          }
       }
      

      这里是 NuGet

      Install-Package Octokit
      

      【讨论】:

      • 注意:如果 TagName 不仅包含点分隔的数字,例如“v1.0.0”或“3.10.3-rc2”,则除非删除其他字符,否则无法构造 Version 对象。另请注意,Version("1.0.0") &lt; Version("1.0.0.0") 出于某种原因。
      猜你喜欢
      • 2017-12-01
      • 2020-05-19
      • 2019-05-06
      • 1970-01-01
      • 2020-07-26
      • 1970-01-01
      • 2014-02-21
      • 2013-05-12
      • 2021-11-25
      相关资源
      最近更新 更多