开发者

Install NuGet package programmatically

I'm trying to install a simple nuget-package programatically. I have created a package with a Site.css file in it. So it resides in the content folder of the package.

Using this code

public void TestInstall(string packageID, string physicalPath)
{
   var rep = PackageRepositoryFactory.Default.CreateRepository(new PackageSource("http://nuget.testserver.lan/nuget", "Default"));

   var packagemgr = new PackageManager(
                rep,
                new DefaultPackagePathResolver("http://nuget.testserver.lan/nuget"),
                    new PhysicalFileSystem(physicalPath)
                    );

   var package = rep.FindPackagesById(packageID).First();

   packagemgr.InstallPackage(package, false);
}

Lets say I provide packageID = 'Testpackage' and physicalPath = 'c:\inetpub\test' it creates:

c:\Inetpub\test\Testpackage

and that folder contains:

the content folder with the Site.css A开发者_运维百科ND the Testpackage.0.1.nupkg

Not quite what I'm trying to do but sort of :)

Is it possible to change it so:

  • I can specify where it should place the package for its cache-functionality

  • Make it place whatever resides in the content folder to the specified path?

  • If the package contains dll's in the lib-folder have them go in the bin-directory (create if not exist)


A lot of the functionality of NuGet currently relies on Visual Studio automation, so outside of VS it's difficult to get all of the same behaviour.

Lot of people have asked for functionality that would require changes from using VS automation, so I suspect it's probably on the roadmap, as it's significant work, I don't think it will be soon.

Don't forget you can install packages in the Visual Package Manager console, so it's only a single command (Install-Package MarkdownHelper) and doesn't require clicking through the UI.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜