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

Fixes 3352 - copy local has no effect when opening project in vs2017 #3356

Merged
merged 5 commits into from
Sep 20, 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
46 changes: 33 additions & 13 deletions src/Paket.Core/Installation/RestoreProcess.fs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,19 @@ open Chessie.ErrorHandling
open System.Reflection
open Requirements

// "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, 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) =
let lockFileName = DependenciesFile.FindLockfile dependenciesFileName
Expand Down Expand Up @@ -271,7 +284,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 =
Expand All @@ -280,8 +293,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
Expand All @@ -293,10 +306,12 @@ let createPaketPropsFile (lockFile:LockFile) (cliTools:ResolvedPackage seq) (pac

let packageReferences =
packages
|> Seq.collect (fun (p,_) ->
[sprintf """ <PackageReference Include="%O">""" p.Name
sprintf """ <Version>%O</Version>""" p.Version
""" </PackageReference>"""])
|> Seq.collect (fun (p,_,packageSettings) ->
[yield sprintf """ <PackageReference Include="%O">""" p.Name
yield sprintf """ <Version>%O</Version>""" p.Version
if CombineCopyLocal p.Settings packageSettings = Some false then
yield """ <ExcludeAssets>runtime</ExcludeAssets>"""
yield """ </PackageReference>"""])

[yield sprintf " <ItemGroup Condition=\"($(DesignTimeBuild) == true)%s\">" condition
yield! packageReferences
Expand Down Expand Up @@ -398,18 +413,23 @@ let createProjectReferencesFiles (lockFile:LockFile) (projectFile:ProjectFile) (
if restore then
let direct = allDirectPackages.Contains packageName
let package = resolved.Force().[key]
let combinedCopyLocal = CombineCopyLocal resolvedPackage.Settings packageSettings
let privateAssetsAll =
match combinedCopyLocal with
| Some true -> "true"
| Some false
| None -> "false"
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 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
Expand Down
3 changes: 2 additions & 1 deletion src/Paket.Core/embedded/Paket.Restore.targets
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,12 @@
<PackageName>$([System.String]::Copy('%(PaketReferencesFileLines.Identity)').Split(',')[0])</PackageName>
<PackageVersion>$([System.String]::Copy('%(PaketReferencesFileLines.Identity)').Split(',')[1])</PackageVersion>
<AllPrivateAssets>$([System.String]::Copy('%(PaketReferencesFileLines.Identity)').Split(',')[4])</AllPrivateAssets>
<CopyLocal>$([System.String]::Copy('%(PaketReferencesFileLines.Identity)').Split(',')[5])</CopyLocal>
</PaketReferencesFileLinesInfo>
<PackageReference Include="%(PaketReferencesFileLinesInfo.PackageName)">
<Version>%(PaketReferencesFileLinesInfo.PackageVersion)</Version>
<PrivateAssets Condition=" ('%(PaketReferencesFileLinesInfo.AllPrivateAssets)' == 'true') Or ('$(PackAsTool)' == 'true') ">All</PrivateAssets>
<ExcludeAssets Condition="%(PaketReferencesFileLinesInfo.AllPrivateAssets) == 'exclude'">runtime</ExcludeAssets>
<ExcludeAssets Condition="%(PaketReferencesFileLinesInfo.CopyLocal) == 'false'">runtime</ExcludeAssets>
<Publish Condition=" '$(PackAsTool)' == 'true' ">true</Publish>
</PackageReference>
</ItemGroup>
Expand Down