diff --git a/src/app/FakeLib/MSBuildHelper.fs b/src/app/FakeLib/MSBuildHelper.fs index e81de03dd45..6ea9f4b5641 100644 --- a/src/app/FakeLib/MSBuildHelper.fs +++ b/src/app/FakeLib/MSBuildHelper.fs @@ -3,10 +3,8 @@ module Fake.MSBuildHelper open System -open System.Text open System.IO open System.Configuration -open System.Xml open System.Xml.Linq /// An type to represent MSBuild project files. @@ -113,6 +111,12 @@ type MSBuildFileLoggerConfig = Verbosity : MSBuildVerbosity option Parameters : MSBuildLogParameter list option } +type MSBuildDistributedLoggerConfig = + { + ClassName : string option + AssemblyPath : string + Parameters : (string * string) list option } + /// A type for MSBuild task parameters type MSBuildParams = { Targets : string list @@ -122,7 +126,8 @@ type MSBuildParams = ToolsVersion : string option Verbosity : MSBuildVerbosity option NoConsoleLogger : bool - FileLoggers : MSBuildFileLoggerConfig list option } + FileLoggers : MSBuildFileLoggerConfig list option + DistributedLoggers : (MSBuildDistributedLoggerConfig * MSBuildDistributedLoggerConfig option) list option } /// Defines a default for MSBuild task parameters let mutable MSBuildDefaults = @@ -133,12 +138,13 @@ let mutable MSBuildDefaults = ToolsVersion = None Verbosity = None NoConsoleLogger = false - FileLoggers = None } + FileLoggers = None + DistributedLoggers = None } /// [omit] -let getAllParameters targets maxcpu nodeReuse tools verbosity noconsolelogger fileLoggers properties = - if isUnix then [ targets; tools; verbosity; noconsolelogger ] @ fileLoggers @ properties - else [ targets; maxcpu; nodeReuse; tools; verbosity; noconsolelogger ] @ fileLoggers @ properties +let getAllParameters targets maxcpu nodeReuse tools verbosity noconsolelogger fileLoggers distributedFileLoggers properties = + if isUnix then [ targets; tools; verbosity; noconsolelogger ] @ fileLoggers @ distributedFileLoggers @ properties + else [ targets; maxcpu; nodeReuse; tools; verbosity; noconsolelogger ] @ fileLoggers @ distributedFileLoggers @ properties let private serializeArgs args = args @@ -150,7 +156,7 @@ let private serializeArgs args = |> separated " " /// [omit] -let serializeMSBuildParams (p : MSBuildParams) = +let serializeMSBuildParams (p : MSBuildParams) = let verbosityName v = match v with | Quiet -> "q" @@ -158,6 +164,8 @@ let serializeMSBuildParams (p : MSBuildParams) = | Normal -> "n" | Detailed -> "d" | Diagnostic -> "diag" + + let targets = match p.Targets with @@ -194,45 +202,68 @@ let serializeMSBuildParams (p : MSBuildParams) = else None let fileLoggers = - let logParams param = - match param with - | Append -> "Append" - | PerformanceSummary -> "PerformanceSummary" - | Summary -> "Summary" - | NoSummary -> "NoSummary" - | ErrorsOnly -> "ErrorsOnly" - | WarningsOnly -> "WarningsOnly" - | NoItemAndPropertyList -> "NoItemAndPropertyList" - | ShowCommandLine -> "ShowCommandLine" - | ShowTimestamp -> "ShowTimestamp" - | ShowEventId -> "ShowEventId" - | ForceNoAlign -> "ForceNoAlign" - | DisableConsoleColor -> "DisableConsoleColor" - | DisableMPLogging -> "DisableMPLogging" - | EnableMPLogging -> "EnableMPLogging" + let serializeLogger fl = + let logParams param = + match param with + | Append -> "Append" + | PerformanceSummary -> "PerformanceSummary" + | Summary -> "Summary" + | NoSummary -> "NoSummary" + | ErrorsOnly -> "ErrorsOnly" + | WarningsOnly -> "WarningsOnly" + | NoItemAndPropertyList -> "NoItemAndPropertyList" + | ShowCommandLine -> "ShowCommandLine" + | ShowTimestamp -> "ShowTimestamp" + | ShowEventId -> "ShowEventId" + | ForceNoAlign -> "ForceNoAlign" + | DisableConsoleColor -> "DisableConsoleColor" + | DisableMPLogging -> "DisableMPLogging" + | EnableMPLogging -> "EnableMPLogging" + + sprintf "%s%s%s" + (match fl.Filename with + | None -> "" + | Some f -> sprintf "logfile=%s;" f) + (match fl.Verbosity with + | None -> "" + | Some v -> sprintf "Verbosity=%s;" (verbosityName v)) + (match fl.Parameters with + | None -> "" + | Some ps -> + ps + |> List.map (fun p -> sprintf "%s;" (logParams p)) + |> String.concat "") + match p.FileLoggers with | None -> [] | Some fls -> fls - |> List.map - (fun fl -> - Some - ("flp" + (string fl.Number), - sprintf "%s%s%s" - (match fl.Filename with - | None -> "" - | Some f -> sprintf "logfile=%s;" f) - (match fl.Verbosity with - | None -> "" - | Some v -> sprintf "Verbosity=%s;" (verbosityName v)) - (match fl.Parameters with - | None -> "" - | Some ps -> - ps - |> List.map (fun p -> sprintf "%s;" (logParams p)) - |> String.concat ""))) - - getAllParameters targets maxcpu nodeReuse tools verbosity noconsolelogger fileLoggers properties + |> List.map (fun fl -> Some ("flp" + (string fl.Number), serializeLogger fl) ) + + let distributedFileLoggers = + let serializeDLogger (dlogger : MSBuildDistributedLoggerConfig) = + sprintf "%s%s%s" + (match dlogger.ClassName with | None -> "" | Some name -> sprintf "%s," name) + (sprintf "\"%s\"" dlogger.AssemblyPath) + (match dlogger.Parameters with + | None -> "" + | Some vars -> vars + |> List.fold (fun acc (k,v) -> sprintf "%s%s=%s;" acc k v) "" + |> sprintf ";\"%s\"" + ) + + let createLoggerString cl fl = + match fl with + | None -> serializeDLogger cl + | Some l -> sprintf "%s*%s" (serializeDLogger cl) (serializeDLogger l) + + match p.DistributedLoggers with + | None -> [] + | Some dfls -> + dfls + |> List.map(fun (cl, fl) -> Some("dl", createLoggerString cl fl)) + + getAllParameters targets maxcpu nodeReuse tools verbosity noconsolelogger fileLoggers distributedFileLoggers properties |> serializeArgs /// [omit] @@ -252,7 +283,7 @@ let mutable MSBuildLoggers = match buildServer with | BuildServer.AppVeyor -> MSBuildLoggers <- @"""C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll""" :: MSBuildLoggers -| BuildServer.TeamCity -> MSBuildLoggers <- sprintf "%s,\"%s\"" TeamCityLoggerName pathToLogger :: MSBuildLoggers +| BuildServer.TeamCity -> MSBuildLoggers <- sprintf "%s,\"%s\"" TeamCityLoggerName pathToLogger :: MSBuildLoggers | _ -> () /// Runs a MSBuild project @@ -395,8 +426,8 @@ let BuildWebsite outputPath projectFile = let projectDir = (fileInfo projectFile).Directory.FullName let mutable prefix = "" let diff = slashes projectDir - slashes currentDir - for i in 1..diff do - prefix <- prefix + "../" + prefix <- prefix + (String.replicate diff "../") + MSBuildDebug "" "Rebuild" [ projectFile ] |> ignore MSBuild "" "_CopyWebApplication;_BuiltWebOutputGroupOutput" [ "OutDir", prefix + outputPath diff --git a/src/test/testscripts/test1.fsx b/src/test/testscripts/test1.fsx index 436ee1ec006..d1ed7d59b2d 100644 --- a/src/test/testscripts/test1.fsx +++ b/src/test/testscripts/test1.fsx @@ -2,11 +2,55 @@ open Fake -#if MONO -failwith "mono was set" -#else -failwith "mono was not set" -#endif - -if hasBuildParam "test" |> not then - failwith "test param is missing" +Target "blah" (fun _ -> + let simpleConfig = { + ClassName = None + AssemblyPath = "test.dll" + Parameters = None + } + + let nameConfig = {simpleConfig with ClassName = Some "simpleClass"} + let simpleWithParams = {simpleConfig with Parameters = Some [("Verbosity", "High"); ("dupe2", "wat");]} + let fullConfig = {simpleConfig with + ClassName = nameConfig.ClassName + Parameters = simpleWithParams.Parameters} + + let wcl = Some [ + { + ClassName = Some "WorkflowCentralLogger" + AssemblyPath = "C:\Program Files\Microsoft Team Foundation Server 12.0\Tools\Microsoft.TeamFoundation.Build.Server.Logger.dll" + Parameters = + Some [ + "Verbosity", "Normal" + "BuildUri", "vstfs:///Build/Build/364" + "IgnoreDuplicateProjects", "False" + "InformationNodeId", sprintf "%d" 8 + "TargetsNotLogged", "GetNativeManifest,GetCopyToOutputDirectoryItems,GetTargetPath" + "TFSUrl", "https://ctaggart.visualstudio.com/DefaultCollection" + ] + }, + Some { + ClassName = Some "WorkflowForwardingLogger" + AssemblyPath = "C:\Program Files\Microsoft Team Foundation Server 12.0\Tools\Microsoft.TeamFoundation.Build.Server.Logger.dll" + Parameters = + Some [ + "Verbosity", "Normal" + ] + } + ] + + let simpleRun = + [simpleConfig; nameConfig; simpleWithParams; fullConfig] + |> List.map (fun x -> (x, None)) + let complexRun = + [simpleConfig; nameConfig; simpleWithParams; fullConfig] + |> List.map (fun x -> (x, Some fullConfig)) + + [wcl] + |> List.map (fun x -> {MSBuildDefaults with DistributedLoggers = x}) + |> List.map MSBuildHelper.serializeMSBuildParams + |> List.iter (logfn "%s") +) + +RunTargetOrDefault "blah" +