如何在.NET Core中以编程方式从nuget下载nupkg软件包? [英] How to download a nupkg package from nuget programmatically in .NET Core?

查看:184
本文介绍了如何在.NET Core中以编程方式从nuget下载nupkg软件包?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

过去,在.NET Framework中,我使用此示例以编程方式使用nuget

In past with .NET Framework I used this example for working with nuget programmatically

以编程方式玩软件包!

.NET Core是否有等效的来源?

Is there any equivalent source for .NET Core?

//ID of the package to be looked up
string packageID = "EntityFramework";

//Connect to the official package repository
IPackageRepository repo = PackageRepositoryFactory.Default.CreateRepository("https://packages.nuget.org/api/v2");

//Get the list of all NuGet packages with ID 'EntityFramework'       
List<IPackage> packages = repo.FindPackagesById(packageID).ToList();

//Filter the list of packages that are not Release (Stable) versions
packages = packages.Where (item => (item.IsReleaseVersion() == false)).ToList();

//Iterate through the list and print the full name of the pre-release packages to console
foreach (IPackage p in packages)
{
    Console.WriteLine(p.GetFullName());
}

//---------------------------------------------------------------------------

//ID of the package to be looked up
string packageID = "EntityFramework";

//Connect to the official package repository
IPackageRepository repo = PackageRepositoryFactory.Default.CreateRepository("https://packages.nuget.org/api/v2");

//Initialize the package manager
string path = <PATH_TO_WHERE_THE_PACKAGES_SHOULD_BE_INSTALLED>
PackageManager packageManager = new PackageManager(repo, path);

//Download and unzip the package
packageManager.InstallPackage(packageID, SemanticVersion.Parse("5.0.0"));

我想以编程方式下载并安装任何软件包.

I want to download and install any package programmatically.

https://api.nuget.org/v3/index.json

推荐答案

您显示的代码示例使用了.NET Core不支持的NuGet 2.您将需要使用NuGet 3或即将发布的NuGet4.这些API与NuGet 2相比是一个巨大的突破.这些突破性的变化之一是

The code sample you have shown uses NuGet 2 which is not supported on .NET Core. You'll need to use NuGet 3 or the (soon to be released) NuGet 4. These APIs are a huge break from NuGet 2. One of these breaking changes is that NuGet.Core is obsolete on won't be ported to .NET Core.

在docs.microsoft上结帐 NuGet API v3 .com获取有关NuGet 3的信息.在撰写本文时,此文档基本上是一个很大的TODO,并且没有太多信息.

Checkout NuGet API v3 on docs.microsoft.com for info on NuGet 3. At the time of writing, this doc is basically a big TODO and doesn't have much info.

以下是一些更有用的博客文章.

Here are some blog posts that are more useful.

探索NuGet v3库,第1部分 简介和概念

Exploring the NuGet v3 Libraries, Part 1 Introduction and concepts

探索NuGet v3库,第2部分

探索NuGet v3库,第3部分

当然,您始终可以通过NuGet的源代码进行摸索,以查找更多示例.大多数核心逻辑都存在于 https://github.com/nuget/nuget.client 中.

And of course, you can always go spelunking through NuGet's source code to find more examples. Most of the core logic lives in https://github.com/nuget/nuget.client.

这篇关于如何在.NET Core中以编程方式从nuget下载nupkg软件包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆