Quantcast
Channel: Active questions tagged nuget-package - Stack Overflow
Viewing all articles
Browse latest Browse all 3067

Configure NuGet Client SDK to specify a particular framework

$
0
0

I have the following code sample (taken from this Gist) working for downloading a NuGet package and its dependencies to a particular folder:

public async Task<HashSet<PackageIdentity>> InstallPackageAndDependenciesAsync(PackageIdentity identity){    bool allowUnlisted = false;    bool includePrelease = true;    try    {        ResolutionContext resolutionContext = new ResolutionContext(            DependencyBehavior.Lowest,            includePrelease,            allowUnlisted,            VersionConstraints.ExactMajor | VersionConstraints.ExactMinor);        INuGetProjectContext projectContext = new BlankProjectContext(Settings.Settings, new NuGetCustomLogger());        var installActions = await LocalNuGetPackageManager.PreviewInstallPackageAsync(            LocalNuGetPackageManager.PackagesFolderNuGetProject, identity,            resolutionContext, projectContext,            new[] { RemoteNuGetFeed }, Array.Empty<SourceRepository>(),            CancellationToken.None);        var sourceCache = new SourceCacheContext();        await LocalNuGetPackageManager.ExecuteNuGetProjectActionsAsync(LocalNuGetPackageManager.PackagesFolderNuGetProject, installActions, projectContext, sourceCache, CancellationToken.None);        return new HashSet<PackageIdentity>(installActions.Select(action => action.PackageIdentity));    }    catch (Exception ex)    {        throw;    }} 

This works but it downloads the binaries for all supported versions of .NET (.NET standard 2.1, UWP, net45 etc.)

How can I configure it so it will only download package versions appropriate for a specific target framework e.g. .NET 6.0?


Viewing all articles
Browse latest Browse all 3067

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>