【发布时间】: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
类似的东西。
void UpdateCheck()
{
if (GithubApi.GetCurrentRelease().Version > CurrentVersion)
}
我该怎么做?
我找到了一些 API,https://github.com/octokit/octokit.net
但是我找不到这个功能。
【问题讨论】:
标签: c# api github release octokit.net
使用 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
【讨论】:
我用 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
【讨论】:
Version("1.0.0") < Version("1.0.0.0") 出于某种原因。