How to download a nupkg package from nuget programmatically in .NET Core?

后端 未结 2 1292
广开言路
广开言路 2021-02-13 03:31

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

Play with Packages, programmatically!

Is there any equivalent source for

2条回答
  •  情书的邮戳
    2021-02-13 03:41

    Best way to achieve it is by referring NugetDownloader Nuget package in your Project and use it to download any other package programmatically

    Install-Package NugetDownloader

    NuGet Badge

    Source code and help guide on the same is available at : https://github.com/paraspatidar/NugetDownloader

    Here is a quick sample on how to achieve it :

    string packageName="Newtonsoft.json";
    string version="10.2.1.0"; \\optional
    
    \\initilize NugetEngine from NugetDownloader namespaces
    
    NugetEngine nugetEngine = new NugetEngine();
    nugetEngine.GetPackage(packageName, version).Wait();
    

    sample client is also available at https://github.com/paraspatidar/NugetDownloader/tree/master/NugetDownloaderTestConsole

    Alternately In case if you want to build your Nugetdownloader engine from scratch , then you might also refer https://github.com/Azure/azure-functions-host/blob/dev/src/WebJobs.Script/Description/DotNet/PackageManager.cs as it has something similar implementation , but that too much of code understanding and extraction.

提交回复
热议问题