2017-02-11 5 views
8

.नेट फ्रेमवर्क के साथ अतीत में मैं nuget के साथ काम करने के लिए इस उदाहरण का इस्तेमाल किया प्रोग्राम के रूप में.NET कोर में प्रोग्रामेटिक रूप से nuget से nupkg पैकेज को कैसे डाउनलोड करें?

Play with Packages, programmatically!

वहाँ नेट कोर के लिए किसी भी बराबर स्रोत है?

//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 
+2

क्या आपने V3 लिंक को रिपोजिटरी पथ के रूप में उपयोग करके ऐसा करने की कोशिश की है? –

+0

@ मथिवाननकेपी, मैंने कोशिश की लेकिन "NuGet.Core" असेंबली .NET कोर पर काम नहीं करती है। – NBM

उत्तर

6

आपके द्वारा दिखाए गए कोड नमूने में NuGet 2 का उपयोग किया जाता है जो .NET कोर पर समर्थित नहीं है। आपको NuGet 3 या (जल्द ही रिलीज़ होने के लिए) NuGet 4 का उपयोग करना होगा। ये एपीआई NuGet 2 से एक बड़ा ब्रेक है। इनमें से एक ब्रेकिंग परिवर्तन यह है कि NuGet.Core अप्रचलित है जिसे .NET कोर पर पोर्ट नहीं किया जाएगा।

नुक्सेट 3 पर जानकारी के लिए docs.microsoft.com पर चेकआउट NuGet API v3 3. लेखन के समय, यह दस्तावेज़ मूल रूप से एक बड़ा TODO है और इसमें अधिक जानकारी नहीं है।

यहां कुछ ब्लॉग पोस्ट हैं जो अधिक उपयोगी हैं।

Exploring the NuGet v3 Libraries, Part 1 Introduction and concepts

Exploring the NuGet v3 Libraries, Part 2

Exploring the NuGet v3 Libraries, Part 3

और निश्चित रूप से, आप हमेशा NuGet के स्रोत कोड के माध्यम से spelunking अधिक उदाहरण खोजने के लिए जा सकते हैं। अधिकांश कोर तर्क https://github.com/nuget/nuget.client में रहता है।

संबंधित मुद्दे