Skip to content

Commit

Permalink
Add support for dotnet SDK fallback folder
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
csmager committed Jun 8, 2018
1 parent 3bfe0a1 commit a3a94d8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/Paket.Core/Dependencies/NuGet.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand Down
15 changes: 15 additions & 0 deletions src/Paket.Core/Dependencies/NuGetCache.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit a3a94d8

Please sign in to comment.