以编程方式安装 NuGet 包
我正在尝试以编程方式安装一个简单的 nuget-package 。我创建了一个包含 Site.css 文件的包。因此它位于包的内容文件夹中。
使用此代码
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);
}
假设我提供 packageID = 'Testpackage' 和physicalPath = 'c:\inetpub\test' 它创建:
c:\Inetpub\test\Testpackage
并且该文件夹包含:
带有 Site.css 和 Testpackage 的内容文件夹.0.1.nupkg
不完全是我想要做的,但有点:)
是否可以将其更改为:
我可以指定它应该将包放置在其缓存功能的位置
使其将内容文件夹中的所有内容放置到指定路径?
如果包在 lib 文件夹中包含 dll,请将它们放入 bin 目录(如果不存在则创建)
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 AND 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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
NuGet 的许多功能目前都依赖于 Visual Studio 自动化,因此在 VS 之外很难获得所有相同的行为。
很多人都要求使用 VS 自动化来实现需要更改的功能,所以我怀疑它可能已经在路线图上,因为这是一项重要的工作,我认为不会很快。
不要忘记您可以在可视化包管理器控制台中安装包,因此它只是一个命令 (
Install-Package MarkdownHelper
),不需要单击 UI。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.