diff --git a/integrationtests/Paket.IntegrationTests/BindingRedirect.fs b/integrationtests/Paket.IntegrationTests/BindingRedirect.fs index 86614fac80..5660e23bcc 100644 --- a/integrationtests/Paket.IntegrationTests/BindingRedirect.fs +++ b/integrationtests/Paket.IntegrationTests/BindingRedirect.fs @@ -4,6 +4,7 @@ open System open System.IO open NUnit.Framework open FsUnit +open System.Text.RegularExpressions [] let ``install should redirect required assemblies only``() = @@ -75,4 +76,146 @@ let ``#1195 should report broken app.config``() = paket "install --redirects" "i001195-broken-appconfig" |> ignore failwith "paket should fail" with - | exn when exn.Message.Contains("Project1") && exn.Message.Contains("app.config") -> () \ No newline at end of file + | exn when exn.Message.Contains("Project1") && exn.Message.Contains("app.config") -> () + +[] +let ``#1218 install hard should replace all assembly redirects with required only``() = + paket "install --redirects --createnewbindingfiles --hard" "i001218-binding-redirect-replaces-all-redirects-with-required-only" |> ignore + + let path = Path.Combine(scenarioTempPath "i001218-binding-redirect-replaces-all-redirects-with-required-only") + let config1Path = Path.Combine(path, "Project1", "app.config") + let config2Path = Path.Combine(path, "Project2", "app.config") + let config3Path = Path.Combine(path, "Project3", "app.config") + let config4Path = Path.Combine(path, "Project4", "app.config") + + let config1 = File.ReadAllText(config1Path) + let config2 = File.ReadAllText(config2Path) + let config3 = File.ReadAllText(config3Path) + let config4 = File.ReadAllText(config4Path) + + let Albedo = """""" + let AutoFixture = """""" + let ``AutoFixture.Idioms`` = """""" + let ``AutoFixture.Xunit`` = """""" + let log4net = """""" + let ``Newtonsoft.Json`` = """""" + let ``Newtonsoft.Json.Schema`` = """""" + let xunit = """""" + let ``xunit.extensions`` = """""" + let ``Castle.Core`` = """""" + let ``Castle.Windsor`` = """""" + + config1 |> shouldContainText Albedo + config1 |> shouldContainText AutoFixture + config1.Contains ``AutoFixture.Idioms`` |> shouldEqual false + config1.Contains ``AutoFixture.Xunit`` |> shouldEqual false + config1.Contains log4net |> shouldEqual false + config1 |> shouldContainText ``Newtonsoft.Json`` + config1.Contains ``Newtonsoft.Json.Schema`` |> shouldEqual false + config1.Contains xunit |> shouldEqual false + config1 |> shouldContainText ``xunit.extensions`` + config1 |> shouldContainText ``Castle.Core`` + config1.Contains ``Castle.Windsor`` |> shouldEqual false + + config2.Contains " shouldEqual false + + config3.Contains Albedo |> shouldEqual false + config3.Contains AutoFixture |> shouldEqual false + config3.Contains ``AutoFixture.Idioms`` |> shouldEqual false + config3.Contains ``AutoFixture.Xunit`` |> shouldEqual false + config3.Contains log4net |> shouldEqual false + config3 |> shouldContainText ``Newtonsoft.Json`` + config3.Contains ``Newtonsoft.Json.Schema`` |> shouldEqual false + config3.Contains xunit |> shouldEqual false + config3.Contains ``xunit.extensions`` |> shouldEqual false + config3 |> shouldContainText ``Castle.Core`` + config3.Contains ``Castle.Windsor`` |> shouldEqual false + + config4.Contains Albedo |> shouldEqual false + config4.Contains AutoFixture |> shouldEqual false + config4.Contains ``AutoFixture.Idioms`` |> shouldEqual false + config4.Contains ``AutoFixture.Xunit`` |> shouldEqual false + config4.Contains log4net |> shouldEqual false + config4.Contains ``Newtonsoft.Json`` |> shouldEqual false + config4.Contains ``Newtonsoft.Json.Schema`` |> shouldEqual false + config4.Contains xunit |> shouldEqual false + config4.Contains ``xunit.extensions`` |> shouldEqual false + config4 |> shouldContainText ``Castle.Core`` + config4.Contains ``Castle.Windsor`` |> shouldEqual false + +[] +let ``#1218 install should replace paket's binding redirects with required only``() = + paket "install --redirects --createnewbindingfiles" "i001218-binding-redirect-replaces-all-redirects-with-required-only" |> ignore + + let path = Path.Combine(scenarioTempPath "i001218-binding-redirect-replaces-all-redirects-with-required-only") + let config1Path = Path.Combine(path, "Project1", "app.config") + let config2Path = Path.Combine(path, "Project2", "app.config") + let config3Path = Path.Combine(path, "Project3", "app.config") + let config4Path = Path.Combine(path, "Project4", "app.config") + + let config1 = File.ReadAllText(config1Path) + let config2 = File.ReadAllText(config2Path) + let config3 = File.ReadAllText(config3Path) + let config4 = File.ReadAllText(config4Path) + + let paketMark = "True\s*" + + let Albedo = """""" + let AutoFixture = """""" + let ``AutoFixture.Idioms`` = """""" + let ``AutoFixture.Xunit`` = """""" + let log4net = """""" + let ``Newtonsoft.Json`` = """""" + let ``Newtonsoft.Json.Schema`` = """""" + let xunit = """""" + let ``xunit.extensions`` = """""" + let ``Castle.Core`` = """""" + let ``Castle.Windsor`` = """""" + + Regex.IsMatch(config1, paketMark + Albedo) |> shouldEqual true + Regex.IsMatch(config1, paketMark + AutoFixture) |> shouldEqual true + config1.Contains ``AutoFixture.Idioms`` |> shouldEqual false + config1.Contains ``AutoFixture.Xunit`` |> shouldEqual false + config1.Contains log4net |> shouldEqual false + Regex.IsMatch(config1, paketMark + ``Newtonsoft.Json``) |> shouldEqual true + config1.Contains ``Newtonsoft.Json.Schema`` |> shouldEqual false + config1.Contains xunit |> shouldEqual false + Regex.IsMatch(config1, paketMark + ``xunit.extensions``) |> shouldEqual true + Regex.IsMatch(config1, paketMark + ``Castle.Core``) |> shouldEqual true + config1.Contains ``Castle.Windsor`` |> shouldEqual false + + config2.Contains Albedo |> shouldEqual false + config2.Contains AutoFixture |> shouldEqual false + config2.Contains ``AutoFixture.Idioms`` |> shouldEqual false + config2.Contains ``AutoFixture.Xunit`` |> shouldEqual false + config2.Contains log4net |> shouldEqual false + config2 |> shouldContainText ``Newtonsoft.Json`` + config2.Contains ``Newtonsoft.Json.Schema`` |> shouldEqual false + config2.Contains xunit |> shouldEqual false + config2.Contains ``xunit.extensions`` |> shouldEqual false + config2.Contains ``Castle.Core`` |> shouldEqual false + config2.Contains ``Castle.Windsor`` |> shouldEqual false + + config3.Contains Albedo |> shouldEqual false + config3 |> shouldContainText AutoFixture + config3.Contains ``AutoFixture.Idioms`` |> shouldEqual false + config3.Contains ``AutoFixture.Xunit`` |> shouldEqual false + config3.Contains log4net |> shouldEqual false + Regex.IsMatch(config3, paketMark + ``Newtonsoft.Json``) |> shouldEqual true + config3.Contains ``Newtonsoft.Json.Schema`` |> shouldEqual false + config3.Contains xunit |> shouldEqual false + config3.Contains ``xunit.extensions`` |> shouldEqual false + Regex.IsMatch(config3, paketMark + ``Castle.Core``) |> shouldEqual true + config3.Contains ``Castle.Windsor`` |> shouldEqual false + + config4.Contains Albedo |> shouldEqual false + config4.Contains AutoFixture |> shouldEqual false + config4.Contains ``AutoFixture.Idioms`` |> shouldEqual false + config4.Contains ``AutoFixture.Xunit`` |> shouldEqual false + config4.Contains log4net |> shouldEqual false + config4 |> shouldContainText ``Newtonsoft.Json`` + config4.Contains ``Newtonsoft.Json.Schema`` |> shouldEqual false + config4.Contains xunit |> shouldEqual false + config4.Contains ``xunit.extensions`` |> shouldEqual false + Regex.IsMatch(config4, paketMark + ``Castle.Core``) |> shouldEqual true + config4.Contains ``Castle.Windsor`` |> shouldEqual false diff --git a/integrationtests/scenarios/i001218-binding-redirect-replaces-all-redirects-with-required-only/before/Project1/Project1.fsprojtemplate b/integrationtests/scenarios/i001218-binding-redirect-replaces-all-redirects-with-required-only/before/Project1/Project1.fsprojtemplate new file mode 100644 index 0000000000..8f88f70428 --- /dev/null +++ b/integrationtests/scenarios/i001218-binding-redirect-replaces-all-redirects-with-required-only/before/Project1/Project1.fsprojtemplate @@ -0,0 +1,76 @@ + + + + + Debug + AnyCPU + 2.0 + e789c72a-5cfd-436b-8ef1-61aa2852a89f + Library + Project1 + Project1 + v4.5 + 4.3.0.0 + Project1 + + ..\..\ + true + bin\$(Configuration)\ + + + true + full + false + false + DEBUG;TRACE + 3 + bin\Debug\fsharp_project_scaffold_tests.XML + Project + + + + + + + pdbonly + true + true + TRACE + 3 + bin\Release\Project1.xml + + + 11 + + + + + $(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets + + + + + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\FSharp\Microsoft.FSharp.Targets + + + + + + + + + + + Project3 + {3241afe4-afee-4465-a482-5abbc0bf6457} + True + + + + diff --git a/integrationtests/scenarios/i001218-binding-redirect-replaces-all-redirects-with-required-only/before/Project1/paket.references b/integrationtests/scenarios/i001218-binding-redirect-replaces-all-redirects-with-required-only/before/Project1/paket.references new file mode 100644 index 0000000000..7984df5ebe --- /dev/null +++ b/integrationtests/scenarios/i001218-binding-redirect-replaces-all-redirects-with-required-only/before/Project1/paket.references @@ -0,0 +1,3 @@ +AutoFixture.Xunit +AutoFixture.Idioms +Newtonsoft.Json \ No newline at end of file diff --git a/integrationtests/scenarios/i001218-binding-redirect-replaces-all-redirects-with-required-only/before/Project2/Project2.fsprojtemplate b/integrationtests/scenarios/i001218-binding-redirect-replaces-all-redirects-with-required-only/before/Project2/Project2.fsprojtemplate new file mode 100644 index 0000000000..18a6eddbe7 --- /dev/null +++ b/integrationtests/scenarios/i001218-binding-redirect-replaces-all-redirects-with-required-only/before/Project2/Project2.fsprojtemplate @@ -0,0 +1,69 @@ + + + + + Debug + AnyCPU + 2.0 + bdf41042-8cb5-4723-aa90-18c05f9ffe85 + Library + Project2 + Project2 + v4.5 + 4.3.0.0 + Project2 + + ..\..\ + true + bin\$(Configuration)\ + + + true + full + false + false + DEBUG;TRACE + 3 + bin\Debug\fsharp_project_scaffold_tests.XML + Project + + + + + + + pdbonly + true + true + TRACE + 3 + bin\Release\Project2.xml + + + 11 + + + + + $(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets + + + + + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\FSharp\Microsoft.FSharp.Targets + + + + + + + + + + diff --git a/integrationtests/scenarios/i001218-binding-redirect-replaces-all-redirects-with-required-only/before/Project2/app.config b/integrationtests/scenarios/i001218-binding-redirect-replaces-all-redirects-with-required-only/before/Project2/app.config new file mode 100644 index 0000000000..6ba3896e8c --- /dev/null +++ b/integrationtests/scenarios/i001218-binding-redirect-replaces-all-redirects-with-required-only/before/Project2/app.config @@ -0,0 +1,13 @@ + + + + + + + + + TRUE + + + + diff --git a/integrationtests/scenarios/i001218-binding-redirect-replaces-all-redirects-with-required-only/before/Project2/paket.references b/integrationtests/scenarios/i001218-binding-redirect-replaces-all-redirects-with-required-only/before/Project2/paket.references new file mode 100644 index 0000000000..1063d003b9 --- /dev/null +++ b/integrationtests/scenarios/i001218-binding-redirect-replaces-all-redirects-with-required-only/before/Project2/paket.references @@ -0,0 +1 @@ +Newtonsoft.Json \ No newline at end of file diff --git a/integrationtests/scenarios/i001218-binding-redirect-replaces-all-redirects-with-required-only/before/Project3/Project3.fsprojtemplate b/integrationtests/scenarios/i001218-binding-redirect-replaces-all-redirects-with-required-only/before/Project3/Project3.fsprojtemplate new file mode 100644 index 0000000000..ddae90ab6c --- /dev/null +++ b/integrationtests/scenarios/i001218-binding-redirect-replaces-all-redirects-with-required-only/before/Project3/Project3.fsprojtemplate @@ -0,0 +1,76 @@ + + + + + Debug + AnyCPU + 2.0 + 3241afe4-afee-4465-a482-5abbc0bf6457 + Library + Project3 + Project3 + v4.5 + 4.3.0.0 + Project3 + + ..\..\ + true + bin\$(Configuration)\ + + + true + full + false + false + DEBUG;TRACE + 3 + bin\Debug\fsharp_project_scaffold_tests.XML + Project + + + + + + + pdbonly + true + true + TRACE + 3 + bin\Release\Project3.xml + + + 11 + + + + + $(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets + + + + + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\FSharp\Microsoft.FSharp.Targets + + + + + + + + + + + Project4 + {3e02dbb4-ab9c-4495-9b52-4a69ce15eefd} + True + + + + diff --git a/integrationtests/scenarios/i001218-binding-redirect-replaces-all-redirects-with-required-only/before/Project3/app.config b/integrationtests/scenarios/i001218-binding-redirect-replaces-all-redirects-with-required-only/before/Project3/app.config new file mode 100644 index 0000000000..a255a20fad --- /dev/null +++ b/integrationtests/scenarios/i001218-binding-redirect-replaces-all-redirects-with-required-only/before/Project3/app.config @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + True + + + + diff --git a/integrationtests/scenarios/i001218-binding-redirect-replaces-all-redirects-with-required-only/before/Project3/paket.references b/integrationtests/scenarios/i001218-binding-redirect-replaces-all-redirects-with-required-only/before/Project3/paket.references new file mode 100644 index 0000000000..5f131d4347 --- /dev/null +++ b/integrationtests/scenarios/i001218-binding-redirect-replaces-all-redirects-with-required-only/before/Project3/paket.references @@ -0,0 +1,2 @@ +log4net +Newtonsoft.Json.Schema diff --git a/integrationtests/scenarios/i001218-binding-redirect-replaces-all-redirects-with-required-only/before/Project4/Project4.fsprojtemplate b/integrationtests/scenarios/i001218-binding-redirect-replaces-all-redirects-with-required-only/before/Project4/Project4.fsprojtemplate new file mode 100644 index 0000000000..499ccc95a8 --- /dev/null +++ b/integrationtests/scenarios/i001218-binding-redirect-replaces-all-redirects-with-required-only/before/Project4/Project4.fsprojtemplate @@ -0,0 +1,69 @@ + + + + + Debug + AnyCPU + 2.0 + 3e02dbb4-ab9c-4495-9b52-4a69ce15eefd + Library + Project4 + Project4 + v4.5 + 4.3.0.0 + Project4 + + ..\..\ + true + bin\$(Configuration)\ + + + true + full + false + false + DEBUG;TRACE + 3 + bin\Debug\fsharp_project_scaffold_tests.XML + Project + + + + + + + pdbonly + true + true + TRACE + 3 + bin\Release\Project4.xml + + + 11 + + + + + $(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets + + + + + $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\FSharp\Microsoft.FSharp.Targets + + + + + + + + + + diff --git a/integrationtests/scenarios/i001218-binding-redirect-replaces-all-redirects-with-required-only/before/Project4/app.config b/integrationtests/scenarios/i001218-binding-redirect-replaces-all-redirects-with-required-only/before/Project4/app.config new file mode 100644 index 0000000000..a1df924205 --- /dev/null +++ b/integrationtests/scenarios/i001218-binding-redirect-replaces-all-redirects-with-required-only/before/Project4/app.config @@ -0,0 +1,17 @@ + + + + + + + + + + + + + true + + + + diff --git a/integrationtests/scenarios/i001218-binding-redirect-replaces-all-redirects-with-required-only/before/Project4/paket.references b/integrationtests/scenarios/i001218-binding-redirect-replaces-all-redirects-with-required-only/before/Project4/paket.references new file mode 100644 index 0000000000..140a162eeb --- /dev/null +++ b/integrationtests/scenarios/i001218-binding-redirect-replaces-all-redirects-with-required-only/before/Project4/paket.references @@ -0,0 +1 @@ +Castle.Windsor.Extensions \ No newline at end of file diff --git a/integrationtests/scenarios/i001218-binding-redirect-replaces-all-redirects-with-required-only/before/paket.dependencies b/integrationtests/scenarios/i001218-binding-redirect-replaces-all-redirects-with-required-only/before/paket.dependencies new file mode 100644 index 0000000000..5a5a0cb832 --- /dev/null +++ b/integrationtests/scenarios/i001218-binding-redirect-replaces-all-redirects-with-required-only/before/paket.dependencies @@ -0,0 +1,13 @@ +source "http://nuget.org/api/v2" + +nuget Albedo 1.0.2 +nuget AutoFixture 3.36.9 +nuget AutoFixture.Idioms 3.35.1 +nuget AutoFixture.Xunit 3.36.9 +nuget Castle.Core 3.3.3 +nuget Castle.Windsor 3.0.0.3001 +nuget Castle.Windsor.Extensions 2.1.1 +nuget log4net 2.0.3 +nuget Newtonsoft.Json 7.0.1 +nuget Newtonsoft.Json.Schema 1.0.11 +nuget xunit 1.9.2 diff --git a/integrationtests/scenarios/i001218-binding-redirect-replaces-all-redirects-with-required-only/before/paket.lock b/integrationtests/scenarios/i001218-binding-redirect-replaces-all-redirects-with-required-only/before/paket.lock new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/Paket.Core/BindingRedirects.fs b/src/Paket.Core/BindingRedirects.fs index 0868528918..5183f7b51f 100644 --- a/src/Paket.Core/BindingRedirects.fs +++ b/src/Paket.Core/BindingRedirects.fs @@ -7,6 +7,7 @@ open System.Xml.Linq open System.IO open System.Reflection open Paket.Xml.Linq +open System.Xml.XPath /// Represents a binding redirection type BindingRedirect = @@ -49,6 +50,11 @@ let internal setRedirect (doc:XDocument) bindingRedirect = let newRedirect = createElementWithNs "bindingRedirect" [ "oldVersion", "0.0.0.0-999.999.999.999" "newVersion", bindingRedirect.Version ] + + match tryGetElementWithNs "Paket" dependentAssembly with + | Some e -> e.Value <- "True" + | None -> dependentAssembly.AddFirst(XElement(XName.Get("Paket", bindingNs), "True")) + match dependentAssembly |> tryGetElementWithNs "bindingRedirect" with | Some redirect -> redirect.ReplaceWith(newRedirect) | None -> dependentAssembly.Add(newRedirect) @@ -108,33 +114,45 @@ let private addConfigFileToProject project = project.Save()) /// Applies a set of binding redirects to a single configuration file. -let private applyBindingRedirects bindingRedirects (configFilePath:string) = +let private applyBindingRedirects cleanBindingRedirects bindingRedirects (configFilePath:string) = let config = try XDocument.Load(configFilePath, LoadOptions.PreserveWhitespace) with | exn -> failwithf "Parsing of %s failed.%s%s" configFilePath Environment.NewLine exn.Message + let isMarked e = + match tryGetElement (Some bindingNs) "Paket" e with + | Some e -> e.Value.Trim().ToLower() = "true" + | None -> false + + let nsManager = XmlNamespaceManager(NameTable()); + nsManager.AddNamespace("bindings", bindingNs) + config.XPathSelectElements("//bindings:assemblyBinding", nsManager) + |> Seq.collect (fun e -> e.Elements(XName.Get("dependentAssembly", bindingNs))) + |> List.ofSeq + |> List.filter (fun e -> cleanBindingRedirects || isMarked e) + |> List.iter (fun e -> e.Remove()) + let config = Seq.fold setRedirect config bindingRedirects indentAssemblyBindings config config.Save configFilePath /// Applies a set of binding redirects to all .config files in a specific folder. -let applyBindingRedirectsToFolder createNewBindingFiles rootPath bindingRedirects = +let applyBindingRedirectsToFolder createNewBindingFiles cleanBindingRedirects rootPath bindingRedirects = let applyBindingRedirects projectFile = let bindingRedirects = bindingRedirects projectFile - if Seq.isEmpty bindingRedirects |> not then - let path = Path.GetDirectoryName projectFile.FileName - match getConfig Directory.GetFiles path with - | Some c -> Some c - | None -> - match createNewBindingFiles with - | false -> None - | true -> - let config = createAppConfigInDirectory path - addConfigFileToProject projectFile - Some config - |> Option.iter (applyBindingRedirects bindingRedirects) + let path = Path.GetDirectoryName projectFile.FileName + match getConfig Directory.GetFiles path with + | Some c -> Some c + | None -> + match createNewBindingFiles, Seq.isEmpty bindingRedirects with + | true, false -> + let config = createAppConfigInDirectory path + addConfigFileToProject projectFile + Some config + | _ -> None + |> Option.iter (applyBindingRedirects cleanBindingRedirects bindingRedirects) rootPath |> getProjectFilesWithPaketReferences Directory.GetFiles diff --git a/src/Paket.Core/InstallProcess.fs b/src/Paket.Core/InstallProcess.fs index c94dfd6c11..52632f6ca6 100644 --- a/src/Paket.Core/InstallProcess.fs +++ b/src/Paket.Core/InstallProcess.fs @@ -161,7 +161,7 @@ let createModel(root, force, dependenciesFile:DependenciesFile, lockFile : LockF extractedPackages /// Applies binding redirects for all strong-named references to all app. and web.config files. -let private applyBindingRedirects (loadedLibs:Dictionary<_,_>) createNewBindingFiles root groupName findDependencies (extractedPackages:seq<_*InstallModel>) = +let private applyBindingRedirects (loadedLibs:Dictionary<_,_>) createNewBindingFiles cleanBindingRedirects root groupName findDependencies (extractedPackages:seq<_*InstallModel>) = let dependencyGraph = ConcurrentDictionary<_,Set<_>>() let projects = ConcurrentDictionary<_,ProjectFile option>(); @@ -223,8 +223,9 @@ let private applyBindingRedirects (loadedLibs:Dictionary<_,_>) createNewBindingF Version = assembly.GetName().Version.ToString() PublicKeyToken = token Culture = None }) + |> Seq.sort - applyBindingRedirectsToFolder createNewBindingFiles root bindingRedirects + applyBindingRedirectsToFolder createNewBindingFiles cleanBindingRedirects root bindingRedirects let findAllReferencesFiles root = root @@ -376,7 +377,7 @@ let InstallIntoProjects(options : InstallerOptions, dependenciesFile, lockFile : let isEnabled = defaultArg packageRedirects (options.Redirects || g.Value.Options.Redirects) isEnabled && (fst kv.Key) = g.Key) |> Seq.map (fun kv -> kv.Value) - |> applyBindingRedirects loadedLibs options.CreateNewBindingFiles (FileInfo project.FileName).Directory.FullName g.Key lockFile.GetAllDependenciesOf + |> applyBindingRedirects loadedLibs options.CreateNewBindingFiles options.Hard (FileInfo project.FileName).Directory.FullName g.Key lockFile.GetAllDependenciesOf /// Installs all packages from the lock file. let Install(options : InstallerOptions, dependenciesFile, lockFile : LockFile) = diff --git a/tests/Paket.Tests/BindingRedirect.fs b/tests/Paket.Tests/BindingRedirect.fs index 643e60f018..d37c21c90e 100644 --- a/tests/Paket.Tests/BindingRedirect.fs +++ b/tests/Paket.Tests/BindingRedirect.fs @@ -5,6 +5,7 @@ open Paket.BindingRedirects open NUnit.Framework open System.Xml.Linq open FsUnit +open System.Xml let defaultRedirect = { AssemblyName = "Assembly" @@ -21,7 +22,7 @@ let private containsDescendents count ns elementName (doc:XDocument) = Assert.AreEqual(count, doc.Descendants(XName.Get(elementName, ns)) |> Seq.length) let private containsSingleDescendent = containsDescendents 1 "" let private containsSingleDescendentWithNs = containsDescendents 1 bindingNs -let private createBindingRedirectXml culture assembly version publicKey = sprintf "\r\n \r\n \r\n" assembly publicKey culture version +let private createBindingRedirectXml culture assembly version publicKey = sprintf "\r\n True\r\n \r\n \r\n" assembly publicKey culture version let private xNameForNs name = XName.Get(name, bindingNs) let sampleDocWithNoIndentation() = sprintf """ @@ -125,7 +126,7 @@ let ``redirects got properly indented for readability``() = dependency.ToString() |> normalizeLineEndings |> shouldEqual - ("\r\n \r\n \r\n " + ("\r\n True\r\n \r\n \r\n " |> normalizeLineEndings) let toSafePath = System.IO.Path.GetFullPath @@ -161,3 +162,47 @@ let ``project file not containing paket.references is not marked for binding red ] getProjectFilesWithPaketReferences mockGetFiles rootPath |> shouldEqual [] + +[] +let ``adds paket's node if one does not exist``() = + let doc = sampleDoc() + setRedirect doc defaultRedirect |> ignore + + let dependency = doc.Descendants(xNameForNs "dependentAssembly") |> Seq.head + dependency.Nodes() + |> Seq.filter (fun e -> e.NodeType = XmlNodeType.Element) + |> Seq.map (fun e -> e :?> XElement) + |> Seq.filter (fun e -> e.Name = XName.Get("Paket")) + |> List.ofSeq + |> List.iter (fun e -> e.Remove()) + + // Act + setRedirect doc { defaultRedirect with Version = "2.0.0" } |> ignore + + // Assert + let dependency = doc.Descendants(xNameForNs "dependentAssembly") |> Seq.head + dependency.ToString() + |> normalizeLineEndings + |> shouldEqual (createBindingRedirectXml "neutral" "Assembly" "2.0.0" "PUBLIC_KEY" |> normalizeLineEndings) + +[] +let ``replaces paket's node if one already exists``() = + let doc = sampleDoc() + setRedirect doc defaultRedirect |> ignore + + let dependency = doc.Descendants(xNameForNs "dependentAssembly") |> Seq.head + dependency.Nodes() + |> Seq.filter (fun e -> e.NodeType = XmlNodeType.Element) + |> Seq.map (fun e -> e :?> XElement) + |> Seq.filter (fun e -> e.Name = XName.Get("Paket")) + |> List.ofSeq + |> List.iter (fun e -> e.Value <- "False") + + // Act + setRedirect doc { defaultRedirect with Version = "2.0.0" } |> ignore + + // Assert + let dependency = doc.Descendants(xNameForNs "dependentAssembly") |> Seq.head + dependency.ToString() + |> normalizeLineEndings + |> shouldEqual (createBindingRedirectXml "neutral" "Assembly" "2.0.0" "PUBLIC_KEY" |> normalizeLineEndings)