Skip to content

Commit

Permalink
Don't touch app.config if we don't logically change it - references #…
Browse files Browse the repository at this point in the history
  • Loading branch information
forki committed Dec 4, 2015
1 parent 13710f9 commit e4a9407
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 14 deletions.
2 changes: 1 addition & 1 deletion RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#### 2.32.5 - 03.12.2015
#### 2.32.6 - 04.12.2015
* Don't touch app.config if we don't logically change it - https://github.com/fsprojects/Paket/issues/1248

#### 2.32.4 - 03.12.2015
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
<!-- For Goldmine tests -->
<add key="GoldmineEntityType" value="Proxy" />
<!-- Google apps API keys -->
<add key="GoogleAppMigrationWizProjectApiKey-1" value="key1" />
<add key="GoogleAppMigrationWizProjectApiKey-2" value="key2" />
<add key="GoogleAppMigrationWizProjectApiKey-1" value="key1"/>
<add key="GoogleAppMigrationWizProjectApiKey-2" value="key2"/>
<add key="GoogleAppMigrationWizProjectApiKey-3" value="key3"/>
<add key="SendEmails" value="false"/>
<add key="BitTitanDropBoxAppKey" value="BitTitan" />
Expand All @@ -14,4 +14,4 @@
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
<runtime><assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1" /></runtime></configuration>
</configuration>
16 changes: 11 additions & 5 deletions src/Paket.Core/BindingRedirects.fs
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,14 @@ let internal indentAssemblyBindings config =

let parent = assemblyBinding.Parent
assemblyBinding.Remove()
let newAssemblyBindingNode = XElement.Parse(sb.ToString(), LoadOptions.PreserveWhitespace)
parent.Add(newAssemblyBindingNode)
let newText = sb.ToString()
let newAssemblyBindingNode = XElement.Parse(newText, LoadOptions.PreserveWhitespace)

if newAssemblyBindingNode.HasElements then
parent.Add(newAssemblyBindingNode)
else
if not parent.HasElements then
parent.Remove()

let private configFiles = [ "app"; "web" ] |> Set.ofList
let private projectFiles = [ ".csproj"; ".vbproj"; ".fsproj"; ".wixproj" ] |> Set.ofList
Expand Down Expand Up @@ -123,7 +129,7 @@ let private applyBindingRedirects isFirstGroup cleanBindingRedirects bindingRedi
with
| exn -> failwithf "Parsing of %s failed.%s%s" configFilePath Environment.NewLine exn.Message

let original = config.ToString(SaveOptions.None)
let original = config.ToString(SaveOptions.None).Replace("\r","").Replace("\n","")

let isMarked e =
match tryGetElement (Some bindingNs) "Paket" e with
Expand All @@ -140,7 +146,7 @@ let private applyBindingRedirects isFirstGroup cleanBindingRedirects bindingRedi

let config = Seq.fold setRedirect config bindingRedirects
indentAssemblyBindings config
let newText = config.ToString(SaveOptions.None)
let newText = config.ToString(SaveOptions.None).Replace("\r","").Replace("\n","")
if newText <> original then
config.Save(configFilePath, SaveOptions.DisableFormatting)

Expand All @@ -164,7 +170,7 @@ let applyBindingRedirectsToFolder isFirstGroup createNewBindingFiles cleanBindin
|> getProjectFilesWithPaketReferences Directory.GetFiles
|> Seq.map ProjectFile.TryLoad
|> Seq.choose id
|> Seq.iter (applyBindingRedirects)
|> Seq.iter applyBindingRedirects

/// Calculates the short form of the public key token for use with binding redirects, if it exists.
let getPublicKeyToken (assembly:Assembly) =
Expand Down
26 changes: 21 additions & 5 deletions tests/Paket.Tests/BindingRedirect.fs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ open System.Xml.Linq
open FsUnit
open System.Xml

let defaultRedirect =
{ AssemblyName = "Assembly"
Version = "1.0.0"
PublicKeyToken = "PUBLIC_KEY"
Culture = None }
let defaultRedirect =
{ AssemblyName = "Assembly"
Version = "1.0.0"
PublicKeyToken = "PUBLIC_KEY"
Culture = None }

let emptySampleDoc() =
let doc = """<?xml version="1.0" encoding="utf-8"?>
Expand Down Expand Up @@ -164,6 +164,22 @@ let ``redirects got properly indented for readability in empty sample docs``() =
|> normalizeLineEndings
|> shouldEqual (normalizeLineEndings expected)

[<Test>]
let ``redirect tags are removed if we have no redirect empty sample docs``() =
let doc = emptySampleDoc()

// Act
indentAssemblyBindings doc

let expected = """
<configuration>
</configuration>"""

// Assert
doc.ToString(SaveOptions.DisableFormatting)
|> normalizeLineEndings
|> shouldEqual (normalizeLineEndings expected)

[<Test>]
let ``redirects got properly indented for readability in sample doc with runtime``() =
let doc = sampleDocWithRuntime()
Expand Down

0 comments on commit e4a9407

Please sign in to comment.