Skip to content

Instantly share code, notes, and snippets.

@TWith2Sugars
Last active January 28, 2016 14:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TWith2Sugars/d89f59e21efc0f094724 to your computer and use it in GitHub Desktop.
Save TWith2Sugars/d89f59e21efc0f094724 to your computer and use it in GitHub Desktop.
Conform all fsproj
#r @"packages/Paket.Core/lib/net45/Paket.Core.dll"
open Paket
open Paket.Xml
open System.Xml
let setProjectAttribute attribute innerText (propertyGroup:Xml.XmlNode) =
let nodes = propertyGroup.ChildNodes |> Seq.cast<XmlNode> |> Seq.filter(fun node -> node.Name = attribute )
nodes |> Seq.iter(propertyGroup.RemoveChild >> ignore)
let attribute = propertyGroup.OwnerDocument.CreateElement(attribute, Constants.ProjectDefaultNameSpace)
match innerText with
| null -> ()
| _ -> attribute.InnerText <- innerText
propertyGroup.AppendChild attribute |> ignore
propertyGroup
let targetFrameworkVersion = setProjectAttribute "TargetFrameworkVersion" "v4.6"
let targetFSharpCoreVersion = setProjectAttribute "TargetFSharpCoreVersion" "4.4.0.0"
let prefere64Bit = setProjectAttribute "Prefer32Bit" "false"
let treatWarningsAsErrors = setProjectAttribute "TreatWarningsAsErrors" "true"
let warningsAsErrors = setProjectAttribute "WarningsAsErrors" null
let warningLevel = setProjectAttribute "WarningLevel" "5"
let otherFlags = setProjectAttribute "OtherFlags" "--warnon:1182"
let requireAutomaticBindingRedirects = setProjectAttribute "AutoGenerateBindingRedirects" "true"
let requiredCommon =
targetFrameworkVersion
>> targetFSharpCoreVersion
>> treatWarningsAsErrors
>> warningsAsErrors
>> warningLevel
>> otherFlags
>> requireAutomaticBindingRedirects
>> ignore
let requiredEXE = prefere64Bit >> requiredCommon
let requiredConfig projectPath =
let project = ProjectFile.TryLoad projectPath
match project with
| None -> ()
| Some p ->
let propertyGroup = getNodes "PropertyGroup" p.ProjectNode
match p.OutputType with
| Paket.ProjectOutputType.Exe -> propertyGroup |> List.iter requiredEXE
| Paket.ProjectOutputType.Library -> propertyGroup |> List.iter requiredCommon
p.Save()
// Makes sure all proj files have required assemblies
Target "RequiredProjConfig" (fun _ ->
let fsProjs = !! "*/**/*.*proj"
fsProjs |> Seq.iter requiredConfig
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment