From a3a94d88a686e03ef640e73abe9c0e23a74f812f Mon Sep 17 00:00:00 2001 From: Charles Mager Date: Fri, 8 Jun 2018 13:37:28 +0100 Subject: [PATCH] Add support for dotnet SDK fallback folder The dotnet SDK ships with various .NET Core and ASP.NET Core nuget packages in a NuGetFallbackFolder. This changes to try to find packages in that folder before looking in other caches or downloading from source. In the event the package is found here, the contents are copied or linked directly from that folder instead of the user's cache. --- src/Paket.Core/Dependencies/NuGet.fs | 17 ++++++++++++----- src/Paket.Core/Dependencies/NuGetCache.fs | 15 +++++++++++++++ 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/src/Paket.Core/Dependencies/NuGet.fs b/src/Paket.Core/Dependencies/NuGet.fs index b539447725..6c4c1ad621 100644 --- a/src/Paket.Core/Dependencies/NuGet.fs +++ b/src/Paket.Core/Dependencies/NuGet.fs @@ -760,12 +760,14 @@ let private downloadAndExtractPackage(alternativeProjectRoot, root, isLocalOverr let nupkgName = packageName.ToString() + "." + version.ToString() + ".nupkg" let normalizedNupkgName = NuGetCache.GetPackageFileName packageName version let configResolved = config.Resolve root groupName packageName version includeVersionInPath - let targetFileName = + let targetFileName, isTargetInFallbackFolder = if not isLocalOverride then - NuGetCache.GetTargetUserNupkg packageName version + match NuGetCache.TryGetFallbackNupkg None packageName version with + | Some fileName -> fileName, true + | None -> NuGetCache.GetTargetUserNupkg packageName version, false else match configResolved.Path with - | Some p -> Path.Combine(p, nupkgName) + | Some p -> Path.Combine(p, nupkgName), false | None -> failwithf "paket.local in combination with storage:none is not supported" if isLocalOverride && not force then @@ -984,12 +986,17 @@ let private downloadAndExtractPackage(alternativeProjectRoot, root, isLocalOverr | false, otherConfig -> otherConfig.Path |> Option.iter SymlinkUtils.delete - let! extractedUserFolder = ExtractPackageToUserFolder(targetFile.FullName, packageName, version, kind) + let! extractedFolder = async { + if isTargetInFallbackFolder then return Path.GetDirectoryName targetFileName + else return! ExtractPackageToUserFolder(targetFile.FullName, packageName, version, kind) } + let! files = NuGetCache.CopyFromCache(otherConfig, targetFile.FullName, licenseFileName, packageName, version, force, detailed) + let finalFolder = match files with | Some f -> f - | None -> extractedUserFolder + | None -> extractedFolder + return targetFileName,finalFolder } diff --git a/src/Paket.Core/Dependencies/NuGetCache.fs b/src/Paket.Core/Dependencies/NuGetCache.fs index 2b6a5dd0d3..6bb34a7b2b 100644 --- a/src/Paket.Core/Dependencies/NuGetCache.fs +++ b/src/Paket.Core/Dependencies/NuGetCache.fs @@ -331,6 +331,21 @@ let GetTargetUserNupkg (packageName:PackageName) (version:SemVerInfo) = let GetTargetUserToolsFolder (packageName:PackageName) (version:SemVerInfo) = DirectoryInfo(Path.Combine(Constants.UserNuGetPackagesFolder,".tools",packageName.CompareString,version.Normalize())).FullName +let TryGetFallbackFolder () = + let dotnet = if isUnix then "dotnet" else "dotnet.exe" + ProcessHelper.tryFindFileOnPath dotnet |> Option.bind (fun fileName -> + let dotnetDir = Path.GetDirectoryName fileName + let fallbackDir = Path.Combine (dotnetDir, "sdk", "NuGetFallbackFolder") + if Directory.Exists fallbackDir then Some fallbackDir else None) + +let TryGetFallbackNupkg (fallbackFolderOverride:string option) (packageName:PackageName) (version:SemVerInfo) = + match fallbackFolderOverride |> Option.orElseWith TryGetFallbackFolder with + | Some folder -> + let normalizedNupkgName = GetPackageFileName packageName version + let fallbackFile = Path.Combine(folder, packageName.CompareString, version.Normalize(), normalizedNupkgName) |> FileInfo + if fallbackFile.Exists && fallbackFile.Length > 0L then Some fallbackFile.FullName else None + | None -> None + /// Extracts the given package to the user folder let rec ExtractPackageToUserFolder(fileName:string, packageName:PackageName, version:SemVerInfo, kind:PackageResolver.ResolvedPackageKind) = async {