|
1 | 1 | open System |
2 | | -open System.Xml |
| 2 | +open System.Xml.Linq |
3 | 3 | open Fake.Core |
4 | 4 | open Fake.DotNet |
5 | 5 | open Fake.Tools |
@@ -211,34 +211,33 @@ module NuGetConfig = |
211 | 211 |
|
212 | 212 | try |
213 | 213 | if IO.File.Exists nugetConfigPath then |
214 | | - let doc = XmlDocument() |
215 | | - doc.Load(nugetConfigPath) |
| 214 | + let doc = XDocument.Load(nugetConfigPath) |
216 | 215 |
|
217 | | - let configNode = doc.SelectSingleNode("//configuration") |
218 | | - if configNode <> null then |
| 216 | + match doc.Root with |
| 217 | + | null -> |
| 218 | + Trace.logf "Warning: Invalid XML structure in %s" nugetConfigPath |
| 219 | + | configRoot -> |
219 | 220 | // Remove existing packageSourceMapping if it exists |
220 | | - let existingMapping = configNode.SelectSingleNode("packageSourceMapping") |
221 | | - if existingMapping <> null then |
222 | | - configNode.RemoveChild(existingMapping) |> ignore |
| 221 | + configRoot.Element(XName.Get("packageSourceMapping")) |
| 222 | + |> ValueOption.ofObj |
| 223 | + |> ValueOption.iter (fun existingMapping -> existingMapping.Remove()) |
223 | 224 |
|
224 | 225 | // Create new packageSourceMapping element |
225 | | - let packageSourceMapping = doc.CreateElement("packageSourceMapping") |
| 226 | + let packageSourceMapping = XElement(XName.Get("packageSourceMapping")) |
226 | 227 |
|
227 | 228 | // Create nuget.org source mapping |
228 | | - let nugetSource = doc.CreateElement("packageSource") |
229 | | - nugetSource.SetAttribute("key", "nuget.org") |
| 229 | + let nugetSource = XElement(XName.Get("packageSource")) |
| 230 | + nugetSource.SetAttributeValue(XName.Get("key"), "nuget.org") |
230 | 231 |
|
231 | | - let nugetPattern = doc.CreateElement("package") |
232 | | - nugetPattern.SetAttribute("pattern", "*") |
| 232 | + let nugetPattern = XElement(XName.Get("package")) |
| 233 | + nugetPattern.SetAttributeValue(XName.Get("pattern"), "*") |
233 | 234 |
|
234 | | - nugetSource.AppendChild(nugetPattern) |> ignore |
235 | | - packageSourceMapping.AppendChild(nugetSource) |> ignore |
236 | | - configNode.AppendChild(packageSourceMapping) |> ignore |
| 235 | + nugetSource.Add(nugetPattern) |
| 236 | + packageSourceMapping.Add(nugetSource) |
| 237 | + configRoot.Add(packageSourceMapping) |
237 | 238 |
|
238 | 239 | doc.Save(nugetConfigPath) |
239 | 240 | Trace.log "Successfully updated NuGet package source mapping" |
240 | | - else |
241 | | - Trace.logf "Warning: Could not find configuration node in %s" nugetConfigPath |
242 | 241 | else |
243 | 242 | Trace.logf "Warning: NuGet config file not found at %s" nugetConfigPath |
244 | 243 | with |
|
0 commit comments