{"id":160,"date":"2013-05-20T00:00:00","date_gmt":"2013-05-20T07:00:00","guid":{"rendered":"http:\/\/devblogs.microsoft.com\/nuget\/play-with-packages"},"modified":"2013-05-20T00:00:00","modified_gmt":"2013-05-20T07:00:00","slug":"play-with-packages","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/dotnet\/play-with-packages\/","title":{"rendered":"Play with Packages, programmatically!"},"content":{"rendered":"<p>One of the many often seen requests, from developers using NuGet, is examples on our NuGet core APIs. The requests range from finding meta-data for the packages to installing the package programmatically. In this blog post, I will provide a few examples of using NuGet Core APIs.<\/p>\n<h3>Getting Started<\/h3>\n<p>To use NuGet Core APIs, install <strong>NuGet.Core<\/strong> NuGet package in your project and add <strong>NuGet<\/strong> namespace to your <strong>using<\/strong> statements.<\/p>\n<h3>Get me the pre-released versions of a package<\/h3>\n<p>Let&#8217;s say you would like to get the list of all pre-released versions of <strong>EntityFramework<\/strong> package. Below is the code snippet that would get you the list using NuGet API v2.<\/p>\n<pre><code>\/\/ID of the package to be looked up \nstring packageID = \"EntityFramework\"; \n\n\/\/Connect to the official package repository \nIPackageRepository repo = PackageRepositoryFactory.Default.CreateRepository(\"https:\/\/packages.nuget.org\/api\/v2\"); \n\n\/\/Get the list of all NuGet packages with ID 'EntityFramework' \nList&lt;IPackage&gt; packages = repo.FindPackagesById(packageID).ToList(); \n\n\/\/Filter the list of packages that are not Release (Stable) versions \npackages = packages.Where (item =&gt; (item.IsReleaseVersion() == false)).ToList(); \n\/\/Iterate through the list and print the full name of the pre-release packages to console \nforeach (IPackage p in packages) \n{ \n  Console.WriteLine(p.GetFullName()); \n}<\/code><\/pre>\n<h3>Help me get a package<\/h3>\n<p>Let&#8217;s say you would like to programmatically download and unzip a package in the path you want. Below is the code snippet that you would use to download and unzip the package in the path specified. The example below downloads and unzips <strong>EntityFramework 5.0.0<\/strong> to one of my projects.<\/p>\n<pre><code>\/\/ID of the package to be looked \nup string packageID = \"EntityFramework\"; \n\n\/\/Connect to the official package repository IPackageRepository\nrepo = PackageRepositoryFactory.Default.CreateRepository(\"https:\/\/packages.nuget.org\/api\/v2\"); \n\n\/\/Initialize the package manager string path = &lt;PATH_TO_WHERE_THE_PACKAGES_SHOULD_BE_INSTALLED&gt;\nPackageManager packageManager = new PackageManager(repo, path); \n\n\/\/Download and unzip the package \npackageManager.InstallPackage(packageID, SemanticVersion.Parse(\"5.0.0\"));<\/code><\/pre>\n<h3>It&#8217;s quite easy, have fun!<\/h3>\n<p>As illustrated by the above examples, trying to work with NuGet packages programmatically is quite easy. Start exploring them today!<\/p>\n<p>-Ranjini<\/p>\n","protected":false},"excerpt":{"rendered":"<p>One of the many often seen requests, from developers using NuGet, is examples on our NuGet core APIs. The requests range from finding meta-data for the packages to installing the package programmatically. In this blog post, I will provide a few examples of using NuGet Core APIs. Getting Started To use NuGet Core APIs, install [&hellip;]<\/p>\n","protected":false},"author":4325,"featured_media":58792,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[7874,646],"tags":[],"class_list":["post-160","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-nuget","category-visual-studio"],"acf":[],"blog_post_summary":"<p>One of the many often seen requests, from developers using NuGet, is examples on our NuGet core APIs. The requests range from finding meta-data for the packages to installing the package programmatically. In this blog post, I will provide a few examples of using NuGet Core APIs. Getting Started To use NuGet Core APIs, install [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts\/160","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/users\/4325"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/comments?post=160"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts\/160\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/media\/58792"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/media?parent=160"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/categories?post=160"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/tags?post=160"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}