NuGet / Home

Repo for NuGet Client issues
Other
1.5k stars 252 forks source link

Allow downloading only thr nupkg files #13006

Open Meir017 opened 1 year ago

Meir017 commented 1 year ago

NuGet Product(s) Involved

NuGet.exe

The Elevator Pitch

to allow working in an closed network we need to upload multiple nupkg files to our internal nuget registry (ex: artifactory).

Additional Context and Details

I'm able to achieve this using nuget's SDK (see https://github.com/Meir017/nupkg-downloader)

using NuGet.Packaging;
using NuGet.Packaging.Signing;
using NuGet.ProjectManagement;

if (args.Length != 2)
{
    Console.WriteLine("Usage: NupkgDownloader <packageId> <packageVersion>");
    Environment.Exit(1);
}

var packageId = args[0];
var packageVersion = args[1];
var package = new PackageIdentity(packageId, NuGetVersion.Parse(packageVersion));

ILogger logger = new ConsoleLogger();
ISettings settings = NullSettings.Instance;
var sourceRepository = CreateSourceRepository();

ISourceRepositoryProvider sourceRepositoryProvider = new SourceRepositoryProvider(new PackageSourceProvider(settings), Repository.Provider.GetCoreV3());
var packagesPath = Path.GetFullPath("./packages");
var packageManager = new NuGetPackageManager(sourceRepositoryProvider, settings, packagesPath);

NuGetProject project = new FolderNuGetProject(packagesPath);
var clientPolicyContext = ClientPolicyContext.GetClientPolicy(settings, logger);
INuGetProjectContext projectContext = new ConsoleProjectContext(logger)
{
    PackageExtractionContext = new PackageExtractionContext(PackageSaveMode.Nuspec, XmlDocFileSaveMode.None, clientPolicyContext, logger)
};

await packageManager.InstallPackageAsync(project, package, new ResolutionContext(), projectContext, sourceRepository, Array.Empty<SourceRepository>(), CancellationToken.None);

SourceRepository CreateSourceRepository()
{
    List<Lazy<INuGetResourceProvider>> providers = new List<Lazy<INuGetResourceProvider>>();
    providers.AddRange(Repository.Provider.GetCoreV3());

    var packageSource = new PackageSource("https://api.nuget.org/v3/index.json");
    return new SourceRepository(packageSource, providers);
}
nkolev92 commented 1 year ago

Hey @Meir017,

There should be simpler ways to achieve that via the SDK. You can check out an implementation of a tool I started some time ago.

https://github.com/nkolev92/PackageDownloader/blob/e4ae058f2458c5fd111195a44e854e5a7b65bf10/src/PackageDownload/DownloadCommand/DownloadCommand.cs#L86-L115

In order to consider adding something like that as a first level command, we would need to know about the scenarios and get more upvotes.

Meir017 commented 1 year ago

@nkolev92 my scenario is to download a package and it's dependencies. The dependencies part is the MVP of this

nkolev92 commented 1 year ago

@Meir017 Does nuget.exe install fit your needs?

Meir017 commented 1 year ago

@nkolev92 I don't want to extract the nupkg files, basically I wabt something like nuget install --DownloadType nupkg

nkolev92 commented 1 year ago

NuGet install has a -PackageSaveMode option, but it seems like all these commands have an implied default, which is a unusual when there's an explicit option, but probably too risky to change. https://github.com/NuGet/NuGet.Client/blob/19d1a116a44313910dc9c9a9d1e274727ad82830/src/NuGet.Clients/NuGet.CommandLine/Commands/DownloadCommandBase.cs#L68-L70

Meir017 commented 1 year ago

@nkolev92 maybe adding a new explict flag for specifying to skip archive extraction?

nkolev92 commented 1 year ago

@Meir017

Sure that could be option, which is why we're keeping this issue open. We're not necessarily prescribing a specific solution yet.

Please refer to https://github.com/NuGet/Home/blob/dev/Issue-Triage-Policy.md. At this point, we want to listen for community feedback and if there's enough feedback on the topic, we can retriage and reprioritize this issue.

Remco-Schoeman commented 2 months ago

Our use-case is that we package our app-suite in nuget packages (1 per app/service), and through the package dependencies can create a customized download for each customer. We want to pre-download all packages before we run the actual installation process that unpacks everything because our customers do not always have stable and fast internet available.

The nuget install <PackageIdHere> -DirectDownload -PackageSaveMode nupkg does almost what we want, except that it also unpacks the nupkg.

A -PackageSaveMode nupkgonly that prevents unpacking would be nice.

So, basically i'm asking for the return of the mirror command that can only mirror to a local folder.