Skip to content

Instantly share code, notes, and snippets.

@emgarten
Last active November 15, 2016 20:28
Show Gist options
  • Save emgarten/0e311730366ef35671f3846874f0d9e9 to your computer and use it in GitHub Desktop.
Save emgarten/0e311730366ef35671f3846874f0d9e9 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using NuGet.Frameworks;
using NuGet.Packaging.Core;
using NuGet.ProjectManagement;
namespace ConsoleApplication5
{
class Program
{
static void Main(string[] args)
{
var projectDir = @"C:\Users\user\Documents\Visual Studio 2015\Projects\ConsoleApplication5\ConsoleApplication5";
foreach (var package in GetInstalledPackages(projectDir).Result)
{
Console.WriteLine(package);
}
}
public static async Task<List<PackageIdentity>> GetInstalledPackages(string projectFolder)
{
var project = new PackagesConfigNuGetProject(projectFolder, new Dictionary<string, object>()
{
{ NuGetProjectMetadataKeys.TargetFramework, NuGetFramework.Parse("net46") },
{ NuGetProjectMetadataKeys.UniqueName, "test" },
{ NuGetProjectMetadataKeys.Name, "test" },
});
var installed = await project.GetInstalledPackagesAsync(CancellationToken.None);
return installed.Select(e => e.PackageIdentity).ToList();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment