我怎样才能检查c#中的github版本?

时间:2014-09-05 04:39:13

标签: c# api github release octokit.net

像这样。

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

我该怎么做?

我创建了一些API,https://github.com/octokit/octokit.net

但我找不到这个功能。

感谢。

2 个答案:

答案 0 :(得分:4)

使用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

答案 1 :(得分:0)

我用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