Skip to content

Instantly share code, notes, and snippets.

@idiotandrobot
Created April 18, 2020 09:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save idiotandrobot/7b9d5637154f3339406e01a77d445a54 to your computer and use it in GitHub Desktop.
Save idiotandrobot/7b9d5637154f3339406e01a77d445a54 to your computer and use it in GitHub Desktop.
using Newtonsoft.Json;
public static async Task<Version> GetLatestVersion()
{
const string latestReleaseRequestUrl =
@"https://api.github.com/repos/{user}/{repo}/releases/latest";
try
{
string versionStr;
using (var wc = new WebClient())
{
wc.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");
versionStr = await wc.DownloadStringTaskAsync(latestReleaseRequestUrl);
}
var versionObj = JsonConvert.DeserializeObject<GithubRelease>(versionStr);
return versionObj == null ? null : new Version(versionObj.TagName);
}
catch (Exception)
{
}
return null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment