Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return the latest msbuild version by default when using vswhere #2287

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 26 additions & 21 deletions src/app/Fake.DotNet.MSBuild/MSBuild.fs
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,11 @@ module private MSBuildExeFromVsWhere =
Directory.EnumerateDirectories(msBuildDir)
|> Seq.map (fun dir -> Path.Combine(dir, "Bin", "MSBuild.exe"))
|> Seq.choose(fun exe ->
if File.Exists(exe) then
let v = FileVersionInfo.GetVersionInfo(exe)
Some (sprintf "%d.0" v.FileMajorPart, Path.GetDirectoryName(exe))
else
None)
if File.Exists(exe) then
let v = FileVersionInfo.GetVersionInfo(exe)
Some (v.FileMajorPart, Path.GetDirectoryName(exe))
else
None)
|> List.ofSeq
else
[]
Expand All @@ -114,13 +114,17 @@ module private MSBuildExeFromVsWhere =
getAllVsPath ()
|> List.collect getAllMsBuildPaths
|> List.groupBy fst
|> List.map (fun (v, dirs) -> v, dirs |> List.map snd)
|> Map.ofList)

let get () = all.Value
|> List.sortByDescending fst
|> List.map (fun (v, dirs) ->
{
Version = sprintf "%d.0" v
Paths = dirs |> List.map snd
}))

let getOrdered (): MSBuildEntry list = all.Value
#else
module private MSBuildExeFromVsWhere =
let get() = Map.empty
let getOrdered(): MSBuildEntry list = List.empty
#endif

module private MSBuildExe =
Expand Down Expand Up @@ -226,8 +230,9 @@ module private MSBuildExe =
defaultArg (visualStudioVersion |> Option.bind dict.TryFind) getAllKnownPaths
|> List.map ((@@) Environment.ProgramFilesX86)
let vsWhereVersionPaths =
let dict = MSBuildExeFromVsWhere.get()
let all = dict |> Map.toList |> List.collect snd
let orderedVersions = MSBuildExeFromVsWhere.getOrdered()
let all = orderedVersions |> List.collect (fun e -> e.Paths)
let dict = toDict orderedVersions
defaultArg (visualStudioVersion |> Option.bind dict.TryFind) all
let fullList = vsWhereVersionPaths @ vsVersionPaths |> List.distinct

Expand Down Expand Up @@ -402,7 +407,7 @@ module MSBuild =
DoRestore = x.DoRestore
NoLogo = x.NoLogo
NodeReuse = x.NodeReuse
RestorePackagesFlag =
RestorePackagesFlag =
x.Properties
|> Seq.tryFind (fun (p,v) -> p = "RestorePackages")
|> (function
Expand All @@ -419,7 +424,7 @@ module MSBuild =
FileLoggers = x.FileLoggers
BinaryLoggers = x.BinaryLoggers
DistributedLoggers = x.DistributedLoggers }

type MSBuildParams with
member internal x.CliArguments = asCliArguments x
member internal oldObj.WithCliArguments (x:CliArguments) = withCliArguments oldObj x
Expand Down Expand Up @@ -587,7 +592,7 @@ module MSBuild =
match p.ConsoleLogParameters with
| [] -> None
| ps -> Some ("clp", loggerParams ps)

let fileLoggers =
let serializeLogger fl =
sprintf "%s%s%s"
Expand All @@ -613,7 +618,7 @@ module MSBuild =
| Some bls ->
bls
|> List.map (fun bl -> Some ("bl", bl) )

let serializeLogger (dlogger : MSBuildLoggerConfig) =
sprintf "%s%s%s"
(match dlogger.ClassName with | None -> "" | Some name -> sprintf "%s," name)
Expand Down Expand Up @@ -666,7 +671,7 @@ module MSBuild =
"/" + k + (if String.isNullOrEmpty v then ""
else ":" + v))
|> Args.toWindowsCommandLine

let buildArgs (setParams : MSBuildParams -> MSBuildParams) =
let p =
MSBuildParams.Create()
Expand All @@ -693,7 +698,7 @@ module MSBuild =
Trace.traceFAKE "Could not detect msbuild version from '%s': %O" exePath e
new Version(13,0,0,0)
cache.GetOrAdd(exePath, System.Func<string,_> (fun _ -> getFromCall()))

let private versionToUseBinLog = System.Version("15.3")
let private versionToUseStructuredLogger = System.Version("14.0")
let internal addBinaryLogger (exePath:string) (callMsbuildExe: string -> string) (args:string) (disableFakeBinLoger:bool) =
Expand Down Expand Up @@ -735,9 +740,9 @@ module MSBuild =
r
else
Trace.traceFAKE "msbuild has not created the binlog file as expected, no warnings or errors are reported using native CI capabilities. Use 'DisableInternalBinLog' to 'true' to disable this warning."
[]
[]
| None ->
#endif
#endif
[]

#if !NO_MSBUILD_BINLOG
Expand Down Expand Up @@ -782,7 +787,7 @@ module MSBuild =
WorkingDirectory = msBuildParams.WorkingDirectory
Arguments = args }
|> Process.setEnvironment msBuildParams.Environment) TimeSpan.MaxValue
try
try
handleAfterRun "msbuild" binlogPath result.ExitCode project
Choice1Of2 result
with e -> Choice2Of2 (e, result)
Expand Down