Using nuget to load packages in my own app

Topics: General
Oct 9, 2014 at 6:24 PM
Suppose I have an application which itself isn't referencing much directly. Instead I want to use NuGet to update packages and then I want to resolve packages and load them dynamically at runtime.

I was going down the route of attempting to write my own package resolver but it struck me that I could just reference NuGet itself and call it from within my app to get the packages. I'm not sure where to begin, can someone give me a pointer into how to properly resolve packages?

I'm assuming its somewhere in this package:
Oct 10, 2014 at 3:01 PM
The NuGet.Core NuGet package will provide you the ability to find NuGet packages. I would probably use the last stable release which is 2.8.2.

You can find NuGet packages (*.nupkg) from a url or a local directory using code similar to:
        string url = "";
        IPackageRepository repo = PackageRepositoryFactory.Default.CreateRepository(url);
        var packages = repo
            .Where(p => p.IsLatestVersion)
            .OrderByDescending(p => p.DownloadCount)

        foreach (IPackage package in packages)
You can get the assemblies from the IPackage however you will need to extract the contents.

ScriptCS has code has finds the compatible dlls from an IPackage and loads them.
Oct 10, 2014 at 5:04 PM
Actually I need to know that also, so thanks!

But, what I am actually looking for is a way to resolve assemblies already downloaded locally. For example, given a path to a packages.config file, what are the paths to all of the packages listed that file?

For example here is my current code:

Is there a similarly simple api for doing this like in the above sample? Sorry for not being as clear as I should have been.
Oct 13, 2014 at 8:56 AM
There are a few classes in NuGet.Core that probably provide you with what you want:


You can point the PackageReferenceRepository at a packages.config file and it will return the packages.

The DefaultPackagePathResolver will resolve an IPackage to its path.
Oct 13, 2014 at 1:51 PM
Perfect, thanks. I will check it out.