Last active
November 15, 2016 20:28
-
-
Save emgarten/0e311730366ef35671f3846874f0d9e9 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 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