Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for dotnet SDK fallback folder #3242

Merged
merged 1 commit into from
Jun 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we do it without calling dotnet?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm just using it to find the folder, it's not executed. I guess the alternative is to try the default folder depending on platform.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah I see. that's neat

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