Created
April 18, 2020 09:36
-
-
Save idiotandrobot/7b9d5637154f3339406e01a77d445a54 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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