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

Adding support for SpecificVersion attribute on assembly references #2413

Merged
merged 4 commits into from
Jun 12, 2017
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
3 changes: 3 additions & 0 deletions src/Paket.Core/Dependencies/DependenciesFileParser.fs
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ module DependenciesFileParser =
| AutodetectFrameworkRestrictions
| ImportTargets of bool
| CopyLocal of bool
| SpecificVersion of bool
| CopyContentToOutputDir of CopyToOutputDirectorySettings
| GenerateLoadScripts of bool option
| ReferenceCondition of string
Expand Down Expand Up @@ -317,6 +318,7 @@ module DependenciesFileParser =
Some (ParserOptions (ParserOption.OmitContent setting))
| String.RemovePrefix "import_targets" trimmed -> Some (ParserOptions (ParserOption.ImportTargets(trimmed.Replace(":","").Trim() = "true")))
| String.RemovePrefix "copy_local" trimmed -> Some (ParserOptions (ParserOption.CopyLocal(trimmed.Replace(":","").Trim() = "true")))
| String.RemovePrefix "specific_version" trimmed -> Some (ParserOptions (ParserOption.SpecificVersion(trimmed.Replace(":","").Trim() = "true")))
| String.RemovePrefix "copy_content_to_output_dir" trimmed ->
let setting =
match trimmed.Replace(":","").Trim() with
Expand Down Expand Up @@ -416,6 +418,7 @@ module DependenciesFileParser =
| ResolverStrategyForTransitives strategy -> { current.Options with ResolverStrategyForTransitives = strategy }
| ResolverStrategyForDirectDependencies strategy -> { current.Options with ResolverStrategyForDirectDependencies = strategy }
| CopyLocal mode -> { current.Options with Settings = { current.Options.Settings with CopyLocal = Some mode } }
| SpecificVersion mode -> { current.Options with Settings = { current.Options.Settings with SpecificVersion = Some mode } }
| CopyContentToOutputDir mode -> { current.Options with Settings = { current.Options.Settings with CopyContentToOutputDirectory = Some mode } }
| ImportTargets mode -> { current.Options with Settings = { current.Options.Settings with ImportTargets = Some mode } }
| FrameworkRestrictions r -> { current.Options with Settings = { current.Options.Settings with FrameworkRestrictions = r } }
Expand Down
6 changes: 6 additions & 0 deletions src/Paket.Core/PaketConfigFiles/LockFile.fs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ module LockFileSerializer =
match options.Settings.CopyLocal with
| Some x -> yield "COPY-LOCAL: " + x.ToString().ToUpper()
| None -> ()
match options.Settings.SpecificVersion with
| Some x -> yield "SPECIFIC-VERSION: " + x.ToString().ToUpper()
| None -> ()
match options.Settings.CopyContentToOutputDirectory with
| Some CopyToOutputDirectorySettings.Always -> yield "COPY-CONTENT-TO-OUTPUT-DIR: ALWAYS"
| Some CopyToOutputDirectorySettings.Never -> yield "COPY-CONTENT-TO-OUTPUT-DIR: NEVER"
Expand Down Expand Up @@ -233,6 +236,7 @@ module LockFileParser =
| GenerateLoadScripts of bool option
| FrameworkRestrictions of FrameworkRestrictions
| CopyLocal of bool
| SpecificVersion of bool
| CopyContentToOutputDir of CopyToOutputDirectorySettings
| Redirects of bool option
| ReferenceCondition of string
Expand Down Expand Up @@ -263,6 +267,7 @@ module LockFileParser =
InstallOption (Redirects setting)
| _, String.RemovePrefix "IMPORT-TARGETS:" trimmed -> InstallOption(ImportTargets(trimmed.Trim() = "TRUE"))
| _, String.RemovePrefix "COPY-LOCAL:" trimmed -> InstallOption(CopyLocal(trimmed.Trim() = "TRUE"))
| _, String.RemovePrefix "SPECIFIC-VERSION:" trimmed -> InstallOption(SpecificVersion(trimmed.Trim() = "TRUE"))
| _, String.RemovePrefix "GENERATE-LOAD-SCRIPTS:" trimmed ->
let setting =
match trimmed.Trim() with
Expand Down Expand Up @@ -351,6 +356,7 @@ module LockFileParser =
| Redirects mode -> { currentGroup.Options with Redirects = mode }
| ImportTargets mode -> { currentGroup.Options with Settings = { currentGroup.Options.Settings with ImportTargets = Some mode } }
| CopyLocal mode -> { currentGroup.Options with Settings = { currentGroup.Options.Settings with CopyLocal = Some mode }}
| SpecificVersion mode -> { currentGroup.Options with Settings = { currentGroup.Options.Settings with SpecificVersion = Some mode }}
| CopyContentToOutputDir mode -> { currentGroup.Options with Settings = { currentGroup.Options.Settings with CopyContentToOutputDirectory = Some mode }}
| FrameworkRestrictions r -> { currentGroup.Options with Settings = { currentGroup.Options.Settings with FrameworkRestrictions = r }}
| OmitContent omit -> { currentGroup.Options with Settings = { currentGroup.Options.Settings with OmitContent = Some omit }}
Expand Down
16 changes: 13 additions & 3 deletions src/Paket.Core/PaketConfigFiles/ProjectFile.fs
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ module ProjectFile =
AnalyzersNode : XmlElement
}

let generateXml (model:InstallModel) (usedFrameworkLibs:HashSet<TargetProfile*string>) (aliases:Map<string,string>) (copyLocal:bool option) (importTargets:bool) (referenceCondition:string option) (allTargetProfiles:Set<TargetProfile>) (project:ProjectFile) : XmlContext =
let generateXml (model:InstallModel) (usedFrameworkLibs:HashSet<TargetProfile*string>) (aliases:Map<string,string>) (copyLocal:bool option) (specificVersion:bool option) (importTargets:bool) (referenceCondition:string option) (allTargetProfiles:Set<TargetProfile>) (project:ProjectFile) : XmlContext =
let references =
getCustomReferenceAndFrameworkNodes project
|> List.map (fun node -> node.Attributes.["Include"].InnerText.Split(',').[0])
Expand Down Expand Up @@ -693,10 +693,20 @@ module ProjectFile =
| Some false -> "False"
| None -> if relativePath.Contains @"\ref\" then "False" else "True"

let specificVersionSettings =
match specificVersion with
| Some true -> "True"
| Some false -> "False"
| None -> "True"

if relativePath.Contains @"\native\" then createNode "NativeReference" project else createNode "Reference" project
|> addAttribute "Include" (fi.Name.Replace(fi.Extension,""))
|> addChild (createNodeSet "HintPath" relativePath project)
|> addChild (createNodeSet "Private" privateSettings project)
|> fun n ->
match specificVersion with
| None -> n
| Some(bool) -> addChild (createNodeSet "SpecificVersion" specificVersionSettings project) n
|> addChild (createNodeSet "Paket" "True" project)
|> fun n ->
match aliases with
Expand Down Expand Up @@ -1057,7 +1067,7 @@ module ProjectFile =
let importTargets = defaultArg installSettings.ImportTargets true

let allFrameworks = applyRestrictionsToTargets restrictionList KnownTargetProfiles.AllProfiles
generateXml projectModel usedFrameworkLibs installSettings.Aliases installSettings.CopyLocal importTargets installSettings.ReferenceCondition (set allFrameworks) project)
generateXml projectModel usedFrameworkLibs installSettings.Aliases installSettings.CopyLocal installSettings.SpecificVersion importTargets installSettings.ReferenceCondition (set allFrameworks) project)
|> Seq.iter (fun ctx ->
for chooseNode in ctx.ChooseNodes do
let i = ref (project.ProjectNode.ChildNodes.Count-1)
Expand Down Expand Up @@ -1461,7 +1471,7 @@ type ProjectFile with

member this.DeleteCustomModelNodes(model:InstallModel) = ProjectFile.deleteCustomModelNodes model this

member this.GenerateXml(model, usedFrameworkLibs:HashSet<TargetProfile*string>, aliases, copyLocal, importTargets, allTargetProfiles:#seq<TargetProfile>, referenceCondition) = ProjectFile.generateXml model usedFrameworkLibs aliases copyLocal importTargets referenceCondition (set allTargetProfiles) this
member this.GenerateXml(model, usedFrameworkLibs:HashSet<TargetProfile*string>, aliases, copyLocal, specificVersion, importTargets, allTargetProfiles:#seq<TargetProfile>, referenceCondition) = ProjectFile.generateXml model usedFrameworkLibs aliases copyLocal specificVersion importTargets referenceCondition (set allTargetProfiles) this

member this.RemovePaketNodes () = ProjectFile.removePaketNodes this

Expand Down
5 changes: 3 additions & 2 deletions src/Paket.Core/PaketConfigFiles/ReferencesFile.fs
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,12 @@ type ReferencesFile =
{ ReferencesFile.FromLines lines with FileName = fileName }
with e -> raise <| new Exception(sprintf "Could not parse reference file '%s': %s" fileName e.Message, e)

member this.AddNuGetReference(groupName, packageName : PackageName, copyLocal: bool, importTargets: bool, frameworkRestrictions, includeVersionInPath, omitContent : bool, createBindingRedirects, referenceCondition) =
member this.AddNuGetReference(groupName, packageName : PackageName, copyLocal: bool, specificVersion: bool, importTargets: bool, frameworkRestrictions, includeVersionInPath, omitContent : bool, createBindingRedirects, referenceCondition) =
let package: PackageInstallSettings =
{ Name = packageName
Settings =
{ CopyLocal = if not copyLocal then Some copyLocal else None
SpecificVersion = if not specificVersion then Some specificVersion else None
CopyContentToOutputDirectory = None
ImportTargets = if not importTargets then Some importTargets else None
FrameworkRestrictions = frameworkRestrictions
Expand Down Expand Up @@ -168,7 +169,7 @@ type ReferencesFile =

{ this with Groups = newGroups }

member this.AddNuGetReference(groupName, packageName : PackageName) = this.AddNuGetReference(groupName, packageName, true, true, ExplicitRestriction FrameworkRestriction.NoRestriction, false, false, None, null)
member this.AddNuGetReference(groupName, packageName : PackageName) = this.AddNuGetReference(groupName, packageName, true, true, true, ExplicitRestriction FrameworkRestriction.NoRestriction, false, false, None, null)

member this.RemoveNuGetReference(groupName, packageName : PackageName) =
let group = this.Groups.[groupName]
Expand Down
11 changes: 11 additions & 0 deletions src/Paket.Core/Versioning/Requirements.fs
Original file line number Diff line number Diff line change
Expand Up @@ -677,13 +677,15 @@ type InstallSettings =
ReferenceCondition : string option
CreateBindingRedirects : BindingRedirectsSettings option
CopyLocal : bool option
SpecificVersion : bool option
Excludes : string list
Aliases : Map<string,string>
CopyContentToOutputDirectory : CopyToOutputDirectorySettings option
GenerateLoadScripts : bool option }

static member Default =
{ CopyLocal = None
SpecificVersion = None
ImportTargets = None
FrameworkRestrictions = ExplicitRestriction FrameworkRestriction.NoRestriction
IncludeVersionInPath = None
Expand All @@ -700,6 +702,9 @@ type InstallSettings =
[ match this.CopyLocal with
| Some x -> yield "copy_local: " + x.ToString().ToLower()
| None -> ()
match this.SpecificVersion with
| Some x -> yield "specific_version: " + x.ToString().ToLower()
| None -> ()
match this.CopyContentToOutputDirectory with
| Some CopyToOutputDirectorySettings.Never -> yield "copy_content_to_output_dir: never"
| Some CopyToOutputDirectorySettings.Always -> yield "copy_content_to_output_dir: always"
Expand Down Expand Up @@ -745,6 +750,7 @@ type InstallSettings =
FrameworkRestrictions = filterRestrictions self.FrameworkRestrictions other.FrameworkRestrictions
OmitContent = self.OmitContent ++ other.OmitContent
CopyLocal = self.CopyLocal ++ other.CopyLocal
SpecificVersion = self.SpecificVersion ++ other.SpecificVersion
CopyContentToOutputDirectory = self.CopyContentToOutputDirectory ++ other.CopyContentToOutputDirectory
ReferenceCondition = self.ReferenceCondition ++ other.ReferenceCondition
Excludes = self.Excludes @ other.Excludes
Expand Down Expand Up @@ -808,6 +814,11 @@ type InstallSettings =
| Some "false" -> Some false
| Some "true" -> Some true
| _ -> None
SpecificVersion =
match getPair "specific_version" with
| Some "false" -> Some false
| Some "true" -> Some true
| _ -> None
GenerateLoadScripts =
match getPair "generate_load_scripts" with
| Some "on" | Some "true" -> Some true
Expand Down
11 changes: 9 additions & 2 deletions tests/Paket.Tests/DependenciesFile/ParserSpecs.fs
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ let ``should read content none config``() =
let cfg = DependenciesFile.FromSource(noneContentConfig)
cfg.Groups.[Constants.MainDependencyGroup].Options.Settings.OmitContent |> shouldEqual (Some ContentCopySettings.Omit)
cfg.Groups.[Constants.MainDependencyGroup].Options.Settings.CopyLocal |> shouldEqual None
cfg.Groups.[Constants.MainDependencyGroup].Options.Settings.SpecificVersion |> shouldEqual None
cfg.Groups.[Constants.MainDependencyGroup].Options.Settings.ImportTargets |> shouldEqual None

cfg.Groups.[Constants.MainDependencyGroup].Sources |> shouldEqual [PackageSource.NuGetV2Source "http://www.nuget.org/api/v2"]
Expand All @@ -232,13 +233,15 @@ let ``should read config with specific framework``() =
let cfg = DependenciesFile.FromSource(specificFrameworkConfig)
cfg.Groups.[Constants.MainDependencyGroup].Options.Settings.OmitContent |> shouldEqual None
cfg.Groups.[Constants.MainDependencyGroup].Options.Settings.CopyLocal |> shouldEqual None
cfg.Groups.[Constants.MainDependencyGroup].Options.Settings.SpecificVersion |> shouldEqual None
cfg.Groups.[Constants.MainDependencyGroup].Options.Settings.ImportTargets |> shouldEqual None

cfg.Groups.[Constants.MainDependencyGroup].Sources |> shouldEqual [PackageSource.NuGetV2Source "http://www.nuget.org/api/v2"]

let noTargetsImportConfig = """
import_targets false
copy_local false
specific_version false
source "http://www.nuget.org/api/v2" // first source

nuget "Microsoft.SqlServer.Types"
Expand All @@ -249,6 +252,7 @@ let ``should read no targets import config``() =
let cfg = DependenciesFile.FromSource(noTargetsImportConfig)
cfg.Groups.[Constants.MainDependencyGroup].Options.Settings.ImportTargets |> shouldEqual (Some false)
cfg.Groups.[Constants.MainDependencyGroup].Options.Settings.CopyLocal |> shouldEqual (Some false)
cfg.Groups.[Constants.MainDependencyGroup].Options.Settings.SpecificVersion |> shouldEqual (Some false)
cfg.Groups.[Constants.MainDependencyGroup].Options.Settings.OmitContent |> shouldEqual None

cfg.Groups.[Constants.MainDependencyGroup].Sources |> shouldEqual [PackageSource.NuGetV2Source "http://www.nuget.org/api/v2"]
Expand Down Expand Up @@ -786,11 +790,12 @@ let ``should read config with framework restriction``() =
p.Settings.FrameworkRestrictions |> getExplicitRestriction |> shouldEqual (makeOrList [FrameworkRestriction.Exactly(DotNetFramework(FrameworkVersion.V3_5)); FrameworkRestriction.AtLeast(DotNetFramework(FrameworkVersion.V4))] |> getExplicitRestriction)
p.Settings.ImportTargets |> shouldEqual None
p.Settings.CopyLocal |> shouldEqual None
p.Settings.SpecificVersion |> shouldEqual None

[<Test>]
let ``should read config with no targets import``() =
let config = """
nuget Foobar 1.2.3 alpha beta import_targets: false, copy_local: false
nuget Foobar 1.2.3 alpha beta import_targets: false, copy_local: false, specific_version: false
"""
let cfg = DependenciesFile.FromSource(config)

Expand All @@ -799,12 +804,13 @@ let ``should read config with no targets import``() =
p.Settings.FrameworkRestrictions |> getExplicitRestriction |> shouldEqual FrameworkRestriction.NoRestriction
p.Settings.ImportTargets |> shouldEqual (Some false)
p.Settings.CopyLocal |> shouldEqual (Some false)
p.Settings.SpecificVersion |> shouldEqual (Some false)
p.Settings.OmitContent |> shouldEqual None

[<Test>]
let ``should read config with content none``() =
let config = """
nuget Foobar 1.2.3 alpha beta content: none, copy_local: false
nuget Foobar 1.2.3 alpha beta content: none, copy_local: false, specific_version: true
"""
let cfg = DependenciesFile.FromSource(config)

Expand All @@ -813,6 +819,7 @@ let ``should read config with content none``() =
p.Settings.FrameworkRestrictions |> getExplicitRestriction |> shouldEqual FrameworkRestriction.NoRestriction
p.Settings.ImportTargets |> shouldEqual None
p.Settings.CopyLocal |> shouldEqual (Some false)
p.Settings.SpecificVersion |> shouldEqual (Some true)
p.Settings.OmitContent |> shouldEqual (Some ContentCopySettings.Omit)

[<Test>]
Expand Down
17 changes: 15 additions & 2 deletions tests/Paket.Tests/DependenciesFile/SaveSpecs.fs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,19 @@ let ``should serialize no local copy config``() =
cfg.ToString()
|> shouldEqual (normalizeLineEndings noLocalCopyConfig)

let noSpecificVersionConfig = """specific_version: false
source http://www.nuget.org/api/v2

nuget FAKE ~> 3.0"""


[<Test>]
let ``should serialize no specific version config``() =
let cfg = DependenciesFile.FromSource(noLocalCopyConfig)

cfg.ToString()
|> shouldEqual (normalizeLineEndings noLocalCopyConfig)

let simplestConfig = """nuget FAKE ~> 3.0"""

[<Test>]
Expand Down Expand Up @@ -236,8 +249,8 @@ let ``should serialize config with framework restrictions``() =
let withNoImportsRestrictions = """source https://www.nuget.org/api/v2

nuget FakeItEasy 1.24.0
nuget json-ld.net 1.0.3 copy_local: false, import_targets: false, framework: net35, net40
nuget Example3 !== 2.2.3 alpha beta import_targets: false
nuget json-ld.net 1.0.3 copy_local: false, import_targets: false, framework: net35, net40, specific_version: true
nuget Example3 !== 2.2.3 alpha beta import_targets: false, specific_version: false
nuget Example4 import_targets: false, content: none
nuget Example5 prerelease import_targets: false

Expand Down
6 changes: 3 additions & 3 deletions tests/Paket.Tests/InstallModel/Xml/CodeCracker.fs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ let ``should generate Xml for codecracker.CSharp``() =

let project = ProjectFile.TryLoad("./ProjectFile/TestData/EmptyCsharpGuid.csprojtest")
Assert.IsTrue(project.IsSome)
let ctx = project.Value.GenerateXml(model, System.Collections.Generic.HashSet<_>() ,Map.empty,Some true,true,KnownTargetProfiles.AllProfiles,None)
let ctx = project.Value.GenerateXml(model, System.Collections.Generic.HashSet<_>() ,Map.empty,Some true,None,true,KnownTargetProfiles.AllProfiles,None)
ctx.AnalyzersNode
|> (fun n -> n.OuterXml)
|> normalizeXml
Expand All @@ -57,7 +57,7 @@ let ``should generate Xml for codecracker.CSharp in VisualBasic project``() =

let project = ProjectFile.TryLoad("./ProjectFile/TestData/EmptyVbGuid.vbprojtest")
Assert.IsTrue(project.IsSome)
let ctx = project.Value.GenerateXml(model, System.Collections.Generic.HashSet<_>(),Map.empty,Some true,true,KnownTargetProfiles.AllProfiles,None)
let ctx = project.Value.GenerateXml(model, System.Collections.Generic.HashSet<_>(),Map.empty,Some true,None,true,KnownTargetProfiles.AllProfiles,None)
ctx.AnalyzersNode
|> (fun n -> n.OuterXml)
|> normalizeXml
Expand Down Expand Up @@ -88,7 +88,7 @@ let ``should generate Xml for codecracker.VisualBasic``() =

let project = ProjectFile.TryLoad("./ProjectFile/TestData/EmptyVbGuid.vbprojtest")
Assert.IsTrue(project.IsSome)
let ctx = project.Value.GenerateXml(model, System.Collections.Generic.HashSet<_>(),Map.empty,Some true,true,KnownTargetProfiles.AllProfiles,None)
let ctx = project.Value.GenerateXml(model, System.Collections.Generic.HashSet<_>(),Map.empty,Some true,None,true,KnownTargetProfiles.AllProfiles,None)
ctx.AnalyzersNode
|> (fun n -> n.OuterXml)
|> normalizeXml
Expand Down
Loading