From 238f938a6ba71bf6cf1fdf06fec7a95a7992e605 Mon Sep 17 00:00:00 2001 From: Atle Rudshaug Date: Tue, 11 Sep 2018 21:29:31 +0200 Subject: [PATCH 1/3] Add ExcludeAssets=runtime in .paket.props when copy_local: false, to avoid VS2017 to change the project.assets.json when opening a project Excract function for combining copy_local from lock and references files --- src/Paket.Core/Installation/RestoreProcess.fs | 41 +++++++++++++------ 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/src/Paket.Core/Installation/RestoreProcess.fs b/src/Paket.Core/Installation/RestoreProcess.fs index 5d05fb988c..f1eed52b87 100644 --- a/src/Paket.Core/Installation/RestoreProcess.fs +++ b/src/Paket.Core/Installation/RestoreProcess.fs @@ -12,6 +12,15 @@ open Chessie.ErrorHandling open System.Reflection open Requirements +/// Combines the copy_local settings from the lock file and the references file +let private CombineCopyLocal (resolvedSettings:InstallSettings) (packageInstallSettings:PackageInstallSettings) = + match resolvedSettings.CopyLocal, packageInstallSettings.Settings.CopyLocal with + | Some false, None + | _, Some false -> Some false + | Some true, None + | _, Some true -> Some true + | None, None -> None + /// Finds packages which would be affected by a restore, i.e. not extracted yet or with the wrong version let FindPackagesNotExtractedYet(dependenciesFileName) = let lockFileName = DependenciesFile.FindLockfile dependenciesFileName @@ -271,7 +280,7 @@ let createPaketPropsFile (lockFile:LockFile) (cliTools:ResolvedPackage seq) (pac "" else packages - |> Seq.map (fun ((groupName,packageName),_,_) -> + |> Seq.map (fun ((groupName,packageName),packageSettings,_) -> let group = lockFile.Groups.[groupName] let p = group.Resolution.[packageName] let restrictions = @@ -280,8 +289,8 @@ let createPaketPropsFile (lockFile:LockFile) (cliTools:ResolvedPackage seq) (pac | FrameworkRestrictions.ExplicitRestriction fw -> FrameworkRestrictions.ExplicitRestriction fw | _ -> group.Options.Settings.FrameworkRestrictions let condition = restrictions |> getExplicitRestriction - p,condition) - |> Seq.groupBy snd + p,condition,packageSettings) + |> Seq.groupBy (fun (_,c,__) -> c) |> Seq.collect (fun (condition,packages) -> let condition = match condition with @@ -293,10 +302,18 @@ let createPaketPropsFile (lockFile:LockFile) (cliTools:ResolvedPackage seq) (pac let packageReferences = packages - |> Seq.collect (fun (p,_) -> - [sprintf """ """ p.Name - sprintf """ %O""" p.Version - """ """]) + |> Seq.collect (fun (p,_,packageSettings) -> + let copy_local = + match CombineCopyLocal p.Settings packageSettings with + | Some false -> false + | Some true + | None -> true + + [yield sprintf """ """ p.Name + yield sprintf """ %O""" p.Version + if copy_local = false then + yield """ runtime""" + yield """ """]) [yield sprintf " " condition yield! packageReferences @@ -399,12 +416,10 @@ let createProjectReferencesFiles (lockFile:LockFile) (projectFile:ProjectFile) ( let direct = allDirectPackages.Contains packageName let package = resolved.Force().[key] let copy_local = - match resolvedPackage.Settings.CopyLocal, packageSettings.Settings.CopyLocal with - | Some false, None - | _, Some false -> "exclude" - | Some true, None - | _, Some true -> "true" - | None, None -> "false" + match CombineCopyLocal resolvedPackage.Settings packageSettings with + | Some false -> "exclude" + | Some true -> "true" + | None -> "false" let line = packageName.ToString() + "," + package.Version.ToString() + "," + From 5e65076ee94251af67dadb7106f756209ad3548a Mon Sep 17 00:00:00 2001 From: Atle Rudshaug Date: Tue, 11 Sep 2018 21:51:24 +0200 Subject: [PATCH 2/3] Inline the CombineCopyLocal check --- src/Paket.Core/Installation/RestoreProcess.fs | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/Paket.Core/Installation/RestoreProcess.fs b/src/Paket.Core/Installation/RestoreProcess.fs index f1eed52b87..19514a60c2 100644 --- a/src/Paket.Core/Installation/RestoreProcess.fs +++ b/src/Paket.Core/Installation/RestoreProcess.fs @@ -303,15 +303,9 @@ let createPaketPropsFile (lockFile:LockFile) (cliTools:ResolvedPackage seq) (pac let packageReferences = packages |> Seq.collect (fun (p,_,packageSettings) -> - let copy_local = - match CombineCopyLocal p.Settings packageSettings with - | Some false -> false - | Some true - | None -> true - [yield sprintf """ """ p.Name yield sprintf """ %O""" p.Version - if copy_local = false then + if CombineCopyLocal p.Settings packageSettings = Some false then yield """ runtime""" yield """ """]) From 373c969cfda4d65a6be3a628693f8fa312c0b9af Mon Sep 17 00:00:00 2001 From: Atle Rudshaug Date: Thu, 13 Sep 2018 23:24:08 +0200 Subject: [PATCH 3/3] Set PrivateAssets=All if only copy_local:true is set for a package in either lock or references file Separated the PrivateAssets and CopyLocal settings in .paket.resolved Added CopyLocal tag in paket.Restore.targets which reads the new column --- src/Paket.Core/Installation/RestoreProcess.fs | 27 +++++++++++++------ src/Paket.Core/embedded/Paket.Restore.targets | 3 ++- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/Paket.Core/Installation/RestoreProcess.fs b/src/Paket.Core/Installation/RestoreProcess.fs index 19514a60c2..31bf5b4e2c 100644 --- a/src/Paket.Core/Installation/RestoreProcess.fs +++ b/src/Paket.Core/Installation/RestoreProcess.fs @@ -12,14 +12,18 @@ open Chessie.ErrorHandling open System.Reflection open Requirements -/// Combines the copy_local settings from the lock file and the references file +// "copy_local: true" is being used to set the "PrivateAssets=All" setting for a package. +// "copy_local: false" in new SDK format is defined as "ExcludeAssets=runtime". +/// Combines the copy_local settings from the lock file and a project's references file let private CombineCopyLocal (resolvedSettings:InstallSettings) (packageInstallSettings:PackageInstallSettings) = match resolvedSettings.CopyLocal, packageInstallSettings.Settings.CopyLocal with - | Some false, None - | _, Some false -> Some false - | Some true, None - | _, Some true -> Some true + | Some false, Some true // E.g. never copy the dll except for unit-test projects | None, None -> None + | _, Some false + | Some false, None -> Some false // Sets ExcludeAssets=runtime + | Some true, Some true + | Some true, None + | None, Some true -> Some true // Sets PrivateAssets=All /// Finds packages which would be affected by a restore, i.e. not extracted yet or with the wrong version let FindPackagesNotExtractedYet(dependenciesFileName) = @@ -409,16 +413,23 @@ let createProjectReferencesFiles (lockFile:LockFile) (projectFile:ProjectFile) ( if restore then let direct = allDirectPackages.Contains packageName let package = resolved.Force().[key] - let copy_local = - match CombineCopyLocal resolvedPackage.Settings packageSettings with - | Some false -> "exclude" + let combinedCopyLocal = CombineCopyLocal resolvedPackage.Settings packageSettings + let privateAssetsAll = + match combinedCopyLocal with | Some true -> "true" + | Some false | None -> "false" + let copy_local = + match combinedCopyLocal with + | Some false -> "false" + | Some true + | None -> "true" let line = packageName.ToString() + "," + package.Version.ToString() + "," + (if direct then "Direct" else "Transitive") + "," + kv.Key.ToString() + "," + + privateAssetsAll + "," + copy_local list.Add line diff --git a/src/Paket.Core/embedded/Paket.Restore.targets b/src/Paket.Core/embedded/Paket.Restore.targets index 6be03acb32..305e736c45 100644 --- a/src/Paket.Core/embedded/Paket.Restore.targets +++ b/src/Paket.Core/embedded/Paket.Restore.targets @@ -144,11 +144,12 @@ $([System.String]::Copy('%(PaketReferencesFileLines.Identity)').Split(',')[0]) $([System.String]::Copy('%(PaketReferencesFileLines.Identity)').Split(',')[1]) $([System.String]::Copy('%(PaketReferencesFileLines.Identity)').Split(',')[4]) + $([System.String]::Copy('%(PaketReferencesFileLines.Identity)').Split(',')[5]) %(PaketReferencesFileLinesInfo.PackageVersion) All - runtime + runtime true