5

像这样的东西。

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

我怎样才能做到这一点?

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

但我找不到这个功能。

4

2 回答 2

5

使用 Octokit.net,您应该能够开始使用文档中的这个示例

得到所有

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

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); 

或者,您可以直接使用 API

列出存储库的版本

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

GET /repos/:owner/:repo/releases
于 2014-09-05T12:26:19.560 回答
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
于 2020-11-26T21:46:47.180 回答