Last active
January 28, 2016 14:44
-
-
Save TWith2Sugars/d89f59e21efc0f094724 to your computer and use it in GitHub Desktop.
Conform all fsproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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