From 530d4ebd5c9141815b1deeccb59095d8ce328a83 Mon Sep 17 00:00:00 2001 From: Steffen Forkmann Date: Sat, 13 May 2017 10:24:47 +0200 Subject: [PATCH] "Dotnet restore" fails on .netstandard projects under 1.6 - fixes #2243 --- RELEASE_NOTES.md | 3 +- src/Paket.Core/Installation/RestoreProcess.fs | 51 ++++++++++++------- .../PaketConfigFiles/InstallModel.fs | 6 --- src/Paket/Paket.fsproj | 6 +-- 4 files changed, 38 insertions(+), 28 deletions(-) diff --git a/RELEASE_NOTES.md b/RELEASE_NOTES.md index a711636aeb..39143ed12d 100644 --- a/RELEASE_NOTES.md +++ b/RELEASE_NOTES.md @@ -1,4 +1,4 @@ -#### 5.0.0-alpha023 - 11.05.2017 +#### 5.0.0-beta001 - 13.05.2017 * BUGFIX: Fixed dotnetcore integration: * Paket now properly understands runtime and reference assemblies * Paket now understands the runtime graph and restores runtime dependencies @@ -13,6 +13,7 @@ * BUGFIX: Sort dependencies on obj/references files - https://github.com/fsprojects/Paket/issues/2310 * BUGFIX: Support .NET moniker ">= monoandroid" - https://github.com/fsprojects/Paket/issues/2246 * BUGFIX: Better dependencies file parser errors +* BUGFIX: "Dotnet restore" failed on .netstandard projects under 1.6 - https://github.com/fsprojects/Paket/issues/2243 * BUGFIX: Paket now accepts multiple nuspec files in fix-nuspec - https://github.com/fsprojects/Paket/pull/2296 * BUGFIX: Fixed pinning of .NETSTANDARD 1.6 packages - https://github.com/fsprojects/Paket/pull/2307 * BUGFIX: Fixed bug with ignored argument of getPackageDetails - https://github.com/fsprojects/Paket/pull/2293 diff --git a/src/Paket.Core/Installation/RestoreProcess.fs b/src/Paket.Core/Installation/RestoreProcess.fs index 839ed58762..268a6a0009 100644 --- a/src/Paket.Core/Installation/RestoreProcess.fs +++ b/src/Paket.Core/Installation/RestoreProcess.fs @@ -190,6 +190,11 @@ let Restore(dependenciesFileName,projectFile,force,group,referencesFileNames,ign if not lockFileName.Exists then failwithf "%s doesn't exist." lockFileName.FullName let dependenciesFile = DependenciesFile.ReadFromFile(dependenciesFileName) + + let targetFilter = + targetFramework + |> Option.bind FrameworkDetection.Extract + let lockFile,localFile,hasLocalFile = let lockFile = LockFile.LoadFrom(lockFileName.FullName) if not localFileName.Exists then @@ -217,6 +222,8 @@ let Restore(dependenciesFileName,projectFile,force,group,referencesFileNames,ign | None -> failwithf "The group %O was not found in the paket.lock file." groupName | Some group -> [groupName,group] |> Map.ofList + let resolved = lazy (lockFile.GetGroupedResolution()) + let referencesFileNames = match projectFile with | Some projectFile -> @@ -235,7 +242,6 @@ let Restore(dependenciesFileName,projectFile,force,group,referencesFileNames,ign ReferencesFile.New fileName - let resolved = lockFile.GetGroupedResolution() let list = System.Collections.Generic.List<_>() let fi = FileInfo projectFile.FileName let newFileName = FileInfo(Path.Combine(fi.Directory.FullName,"obj",fi.Name + ".references")) @@ -246,42 +252,38 @@ let Restore(dependenciesFileName,projectFile,force,group,referencesFileNames,ign createAlternativeNuGetConfig alternativeConfigFileName.FullName + for kv in groups do let hull = lockFile.GetOrderedPackageHull(kv.Key,referencesFile) let depsGroup = match dependenciesFile.Groups |> Map.tryFind kv.Key with | Some group -> group | None -> failwithf "Dependencies file '%s' does not contain group '%O' but it is used in '%s'" dependenciesFile.FileName kv.Key lockFile.FileName + let allDirectPackages = match referencesFile.Groups |> Map.tryFind kv.Key with | Some g -> g.NugetPackages |> List.map (fun p -> p.Name) |> Set.ofList | None -> Set.empty - let target = - targetFramework - |> Option.bind FrameworkDetection.Extract for (key,_,_) in hull do let restore = - match target with + match targetFilter with | None -> true | Some target -> - let (_), (_,model) = - CreateInstallModel(alternativeProjectRoot, root, kv.Key, depsGroup.Sources, depsGroup.Caches, force, resolved.[key]) - |> Async.RunSynchronously - - let refs = model.GetLibReferenceFiles(target) - if not (Seq.isEmpty refs) then - true - else - true + let resolvedPackage = resolved.Force().[key] + match resolvedPackage.Settings.FrameworkRestrictions with + | Requirements.FrameworkRestrictionList restrictions -> + Requirements.isTargetMatchingRestrictions(restrictions, SinglePlatform target) + | _ -> true + if restore then let _,packageName = key let direct = allDirectPackages.Contains packageName let line = packageName.ToString() + "," + - resolved.[key].Version.ToString() + "," + + resolved.Force().[key].Version.ToString() + "," + (if direct then "Direct" else "Transitive") list.Add line @@ -300,10 +302,8 @@ let Restore(dependenciesFileName,projectFile,force,group,referencesFileNames,ign [referencesFile.FileName] | None -> referencesFileNames - - for kv in groups do - let packages = + let allPackages = if List.isEmpty referencesFileNames then kv.Value.Resolution |> Seq.map (fun kv -> kv.Key) @@ -312,6 +312,21 @@ let Restore(dependenciesFileName,projectFile,force,group,referencesFileNames,ign |> List.toSeq |> computePackageHull kv.Key lockFile + let packages = + allPackages + |> Seq.filter (fun p -> + match targetFilter with + | None -> true + | Some target -> + let key = kv.Key,p + let resolvedPackage = resolved.Force().[key] + + match resolvedPackage.Settings.FrameworkRestrictions with + | Requirements.FrameworkRestrictionList restrictions -> + Requirements.isTargetMatchingRestrictions(restrictions, SinglePlatform target) + | _ -> true) + + match dependenciesFile.Groups |> Map.tryFind kv.Value.Name with | None -> failwithf diff --git a/src/Paket.Core/PaketConfigFiles/InstallModel.fs b/src/Paket.Core/PaketConfigFiles/InstallModel.fs index 30713cc44e..dba3d05ffd 100644 --- a/src/Paket.Core/PaketConfigFiles/InstallModel.fs +++ b/src/Paket.Core/PaketConfigFiles/InstallModel.fs @@ -704,7 +704,6 @@ module InstallModel = model |> mapCompileLibFolders(fun folder -> if referenceApplies folder then FrameworkFolder.map (fun c -> { c with FrameworkReferences = Set.add (FrameworkReference.ofName reference.AssemblyName) c.FrameworkReferences }) folder - //{ folder with FolderContents = { folder.FolderContents with FrameworkReferences = Set.add reference.AssemblyName folder.FolderContents.FrameworkReferences } } else folder) @@ -774,11 +773,6 @@ module InstallModel = this |> mapCompileLibReferences (Set.filter (fun reference -> Set.contains reference.Name references |> not)) |> mapCompileLibFrameworkReferences (Set.filter (fun reference -> Set.contains reference.Name references |> not)) - //let inline mapfn (files:InstallFiles) = - // { files with - // References = files.References |> Set.filter (fun reference -> Set.contains reference.ReferenceName references |> not) - // } - //mapFiles mapfn this let addLicense url (model: InstallModel) = if String.IsNullOrWhiteSpace url then model diff --git a/src/Paket/Paket.fsproj b/src/Paket/Paket.fsproj index ab4b2e5835..58bb4ca58b 100644 --- a/src/Paket/Paket.fsproj +++ b/src/Paket/Paket.fsproj @@ -22,7 +22,7 @@ true false false - ..\..\bin\ + C:\temp\PaketRepro\.paket DEBUG;TRACE 3 @@ -30,8 +30,8 @@ Project paket.exe Project - update - D:\temp\TestProject + restore --target-framework netstandard1.3 --project "C:\temp\PaketRepro\PaketRepro\PaketRepro.csproj" + C:\temp\PaketRepro true