3 people like it.
Like the snippet!
Target VS2012 and VS2010
This is a simple script which, recursively walking a folder structure, updates .fsproj files so they may be run in VS2012 or VS2010. This should be run *after* VS2012 has converted a particular solution. Also, I didn't really test it too much, but it worked for me. So there's your disclaimer.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
|
#r "System.Xml.Linq.dll"
open System.IO
open System.Xml
open System.Xml.Linq
let [<Literal>] NS = "http://schemas.microsoft.com/developer/msbuild/2003"
let vs_MinVer = XName.Get("MinimumVisualStudioVersion",NS)
let propGroup = XName.Get("PropertyGroup",NS)
let update file action =
printfn "Loading '%s'..." file
try
let xd = XDocument.Load(file)
printfn "Updating file..."
action xd.Root
printfn "Saving changes..."
xd.Save(file)
printfn "Success!"
with
| x -> printfn "Error: %A" x
let updateAll path pattern action =
Directory.EnumerateFiles(path,pattern,SearchOption.AllDirectories)
|> Seq.iter (fun file -> update file action)
updateAll @"c:\path\to_some\code"
"*.fsproj"
(fun xe -> xe.Descendants(vs_MinVer)
.Ancestors(propGroup)
.Remove())
|
namespace System
namespace System.IO
namespace System.Xml
namespace System.Xml.Linq
Multiple items
type LiteralAttribute =
inherit Attribute
new : unit -> LiteralAttribute
Full name: Microsoft.FSharp.Core.LiteralAttribute
--------------------
new : unit -> LiteralAttribute
val NS : string
Full name: Script.NS
val vs_MinVer : XName
Full name: Script.vs_MinVer
type XName =
member Equals : obj:obj -> bool
member GetHashCode : unit -> int
member LocalName : string
member Namespace : XNamespace
member NamespaceName : string
member ToString : unit -> string
static member Get : expandedName:string -> XName + 1 overload
Full name: System.Xml.Linq.XName
XName.Get(expandedName: string) : XName
XName.Get(localName: string, namespaceName: string) : XName
val propGroup : XName
Full name: Script.propGroup
val update : file:string -> action:(XElement -> unit) -> unit
Full name: Script.update
val file : string
val action : (XElement -> unit)
val printfn : format:Printf.TextWriterFormat<'T> -> 'T
Full name: Microsoft.FSharp.Core.ExtraTopLevelOperators.printfn
val xd : XDocument
Multiple items
type XDocument =
inherit XContainer
new : unit -> XDocument + 3 overloads
member Declaration : XDeclaration with get, set
member DocumentType : XDocumentType
member NodeType : XmlNodeType
member Root : XElement
member Save : fileName:string -> unit + 6 overloads
member WriteTo : writer:XmlWriter -> unit
static member Load : uri:string -> XDocument + 7 overloads
static member Parse : text:string -> XDocument + 1 overload
Full name: System.Xml.Linq.XDocument
--------------------
XDocument() : unit
XDocument([<System.ParamArray>] content: obj []) : unit
XDocument(other: XDocument) : unit
XDocument(declaration: XDeclaration, [<System.ParamArray>] content: obj []) : unit
XDocument.Load(reader: XmlReader) : XDocument
XDocument.Load(textReader: TextReader) : XDocument
XDocument.Load(stream: Stream) : XDocument
XDocument.Load(uri: string) : XDocument
XDocument.Load(reader: XmlReader, options: LoadOptions) : XDocument
XDocument.Load(textReader: TextReader, options: LoadOptions) : XDocument
XDocument.Load(stream: Stream, options: LoadOptions) : XDocument
XDocument.Load(uri: string, options: LoadOptions) : XDocument
property XDocument.Root: XElement
XDocument.Save(writer: XmlWriter) : unit
XDocument.Save(textWriter: TextWriter) : unit
XDocument.Save(stream: Stream) : unit
XDocument.Save(fileName: string) : unit
XDocument.Save(textWriter: TextWriter, options: SaveOptions) : unit
XDocument.Save(stream: Stream, options: SaveOptions) : unit
XDocument.Save(fileName: string, options: SaveOptions) : unit
val x : exn
val updateAll : path:string -> pattern:string -> action:(XElement -> unit) -> unit
Full name: Script.updateAll
val path : string
val pattern : string
type Directory =
static member CreateDirectory : path:string -> DirectoryInfo + 1 overload
static member Delete : path:string -> unit + 1 overload
static member EnumerateDirectories : path:string -> IEnumerable<string> + 2 overloads
static member EnumerateFileSystemEntries : path:string -> IEnumerable<string> + 2 overloads
static member EnumerateFiles : path:string -> IEnumerable<string> + 2 overloads
static member Exists : path:string -> bool
static member GetAccessControl : path:string -> DirectorySecurity + 1 overload
static member GetCreationTime : path:string -> DateTime
static member GetCreationTimeUtc : path:string -> DateTime
static member GetCurrentDirectory : unit -> string
...
Full name: System.IO.Directory
Directory.EnumerateFiles(path: string) : System.Collections.Generic.IEnumerable<string>
Directory.EnumerateFiles(path: string, searchPattern: string) : System.Collections.Generic.IEnumerable<string>
Directory.EnumerateFiles(path: string, searchPattern: string, searchOption: SearchOption) : System.Collections.Generic.IEnumerable<string>
type SearchOption =
| TopDirectoryOnly = 0
| AllDirectories = 1
Full name: System.IO.SearchOption
field SearchOption.AllDirectories = 1
module Seq
from Microsoft.FSharp.Collections
val iter : action:('T -> unit) -> source:seq<'T> -> unit
Full name: Microsoft.FSharp.Collections.Seq.iter
val xe : XElement
XContainer.Descendants() : System.Collections.Generic.IEnumerable<XElement>
XContainer.Descendants(name: XName) : System.Collections.Generic.IEnumerable<XElement>
More information