Skip to content

Instantly share code, notes, and snippets.

@warrenbuckley
Last active November 27, 2016 10:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save warrenbuckley/1380daf1c4f8c6c99d6d to your computer and use it in GitHub Desktop.
Save warrenbuckley/1380daf1c4f8c6c99d6d to your computer and use it in GitHub Desktop.
V3 Nuget API using Nuget.Core Package
using System.Threading;
using System.Threading.Tasks;
using System.Web.Http;
using NuGet.Configuration;
using NuGet.Protocol.Core.Types;
using NuGet.Protocol.Core.v3;
using NuGet.Versioning;
namespace Umbraco.Forms.UpdateChecker.Controller
{
//TODO: Look at WebAPI Cache Output Attributes
//Not built into WebAPI
//From a MS MVP - Filip W (http://www.strathweb.com)
//https://github.com/filipw/AspNetWebApi-OutputCache
[RoutePrefix("api/UpdateChecker")]
public class UpdateCheckerController : ApiController
{
[HttpGet]
[Route("Ping")]
public string Ping()
{
return "Pong";
}
[HttpGet]
[Route("HasUpdate")]
public async Task<string> HasUpdate(string versionNumber)
{
//Check to see if we can find a newer/greater version number on Nuget.org
var repo = Repository.Factory.GetCoreV3(NuGetConstants.V3FeedUrl);
var resource = await repo.GetResourceAsync<MetadataResource>();
var lastestFormsVersion = await resource.GetLatestVersion("UmbracoForms",false,false,CancellationToken.None);
//Parse the current version so we can compare easier
var currentVersion = NuGetVersion.Parse(versionNumber);
if (lastestFormsVersion > currentVersion)
{
return lastestFormsVersion.ToString();
}
return currentVersion.ToString();
}
}
}
@warrenbuckley
Copy link
Author

Thanks to Members of the Nuget.org Dev Team on help me getting started with the new V3 Nuget API

Requires the following Nuget Packages:

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="Microsoft.AspNet.WebApi" version="5.2.3" targetFramework="net452" />
  <package id="Microsoft.AspNet.WebApi.Client" version="5.2.3" targetFramework="net452" />
  <package id="Microsoft.AspNet.WebApi.Core" version="5.2.3" targetFramework="net452" />
  <package id="Microsoft.AspNet.WebApi.WebHost" version="5.2.3" targetFramework="net452" />
  <package id="Microsoft.CodeDom.Providers.DotNetCompilerPlatform" version="1.0.0" targetFramework="net452" />
  <package id="Microsoft.Net.Compilers" version="1.0.0" targetFramework="net452" developmentDependency="true" />
  <package id="Microsoft.Web.Xdt" version="2.1.1" targetFramework="net452" />
  <package id="Newtonsoft.Json" version="6.0.4" targetFramework="net452" />
  <package id="NuGet.Client" version="3.3.0" targetFramework="net452" />
  <package id="NuGet.Configuration" version="3.3.0" targetFramework="net452" />
  <package id="NuGet.ContentModel" version="3.3.0" targetFramework="net452" />
  <package id="NuGet.Core" version="2.10.1" targetFramework="net452" />
  <package id="NuGet.Frameworks" version="3.3.0" targetFramework="net452" />
  <package id="NuGet.Logging" version="3.3.0" targetFramework="net452" />
  <package id="NuGet.Packaging" version="3.3.0" targetFramework="net452" />
  <package id="NuGet.Packaging.Core" version="3.3.0" targetFramework="net452" />
  <package id="NuGet.Packaging.Core.Types" version="3.3.0" targetFramework="net452" />
  <package id="NuGet.Protocol.Core.Types" version="3.3.0" targetFramework="net452" />
  <package id="NuGet.Protocol.Core.v3" version="3.3.0" targetFramework="net452" />
  <package id="NuGet.Repositories" version="3.3.0" targetFramework="net452" />
  <package id="NuGet.RuntimeModel" version="3.3.0" targetFramework="net452" />
  <package id="NuGet.Versioning" version="3.3.0" targetFramework="net452" />
</packages>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment