【发布时间】:2017-02-11 10:15:05
【问题描述】:
在过去的 .NET Framework 中,我使用此示例以编程方式使用 nuget
Play with Packages, programmatically!
.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"));
我想以编程方式下载和安装任何软件包。
https://api.nuget.org/v3/index.json
【问题讨论】:
-
您是否尝试过使用 V3 链接作为存储库路径?
-
@MathivananKP,我试过了,但“NuGet.Core”程序集在 .NET Core 上不起作用。