Help using NuGet.Core PackageManger for an Umbraco NuGet Package Gallery

Topics: General
Jan 8, 2014 at 8:53 AM
Hello all,
I am trying to build a proof of concept code to show that it would be possible to use NuGet packages along with a community MyGet feed for a package repository for the CMS Umbraco.

I have this following code snippet inside a WebAPI Controller for now
public bool GetPackageInstall()
            var repo        = PackageRepositoryFactory.Default.CreateRepository("");
            var path        = new DefaultPackagePathResolver("");
            var fileSystem  = new PhysicalFileSystem(HostingEnvironment.MapPath("~/"));

            //Create a NuGet Package Manager
            var packageManager = new PackageManager(repo, path, fileSystem);

            bool isInstalled = false;

            //Install package
                var packageVersion = SemanticVersion.Parse("2.0.3");

                //Install the package...
                packageManager.InstallPackage("jQuery", packageVersion, false, false);

                //Set flag to true
                isInstalled = true;

            catch (Exception)
                //Some error - set flag to false
                isInstalled = false;

            //Returned bool if it's installed or not
            return isInstalled;        
So with the above code snippet it works to some extent, but is perhaps the results are not quite what I expected.

When running this I get a new folder in the root called jQuery.2.0.3 which contains the Content & Tools folder and the .nupkg file inside as well.

I have checked the Scripts folder at the root and the jQuery file has not been copied into the folder as I would have expected.

What I would like ideally to do is for the jQuery.2.0.3 package folder to be created at App_Plugins/Packages/ for example and the NuGet package to be executed at the root so any files need to be copied over do so from the root directory of the site.

One final thing is would I need to generate myself manually a list of packages that gets installed into the site, or is there a way for me to generate a packages.config file similar to how installing packages using Visual Studio.

I look forward to hearing your thoughts.

Jan 8, 2014 at 9:42 AM
Well you will have to implement this yourself. The package can be installed into App_Plugins byspecifying that path to the PhysicalFileSystem constructor.

After installing the package, you will have to implement the conventions required for your situation, for example:
                var package = packageManager.LocalRepository.FindPackage(packageId, packageVersion);
                if (package != null)
                    // todo: implement conventions here. for example /Content is copied to root of site.
                    foreach (var packageFile in package.GetFiles("Content"))
                        // todo: copy from contents to root
Another option is to implement an IPackagePathResolver which outputs the package on a location you prefer.

One other thing to take into account are package updates: what should happen when a package is updated or uninstalled? Conventions like overwriting content files or not, as well as deleting content files if the package is uninstalled will have to be implemeted as well.