@@ -54,11 +54,22 @@ module Map =
5454 let union loses wins =
5555 Map.fold ( fun acc key value -> Map.add key value acc) loses wins
5656
57- let inline ofDict ( dic ) =
58- dic
57+ let inline ofDict dictionary =
58+ dictionary
5959 |> Seq.map (| KeyValue|)
6060 |> Map.ofSeq
6161
62+
63+ let inline copyToDict ( map : Map < _ , _ >) =
64+ // Have to use a mutable dictionary here because the F# Map doesn't have an Add method
65+ let dictionary = Dictionary<_, _>()
66+
67+ for KeyValue( k, v) in map do
68+ dictionary.Add( k, v)
69+
70+ dictionary :> IDictionary<_, _>
71+
72+
6273module BuildErrorEventArgs =
6374
6475 let messages ( e : BuildErrorEventArgs seq ) =
@@ -244,35 +255,32 @@ module ProjectPropertyInstance =
244255
245256module ProjectLoading =
246257
247- let selectFirstTfm ( projectPath : string ) =
258+ let getAllTfms ( projectPath : string ) =
248259 let pi = ProjectInstance( projectPath)
249260
250- match
261+ pi.Properties
262+ |> ( ProjectPropertyInstance.tryFind " TargetFramework"
263+ >> Option.map Array.singleton)
264+ |> Option.orElseWith ( fun () ->
251265 pi.Properties
252- |> ProjectPropertyInstance.tryFind " TargetFramework"
253- with
254- | Some v -> Some v
255- | None ->
256- match
257- pi.Properties
258- |> ProjectPropertyInstance.tryFind " TargetFrameworks"
259- with
260- | None -> None
261- | Some tfms ->
262- match tfms.Split( ';' ) with
263- | [||] -> None
264- | tfms -> Array.tryHead tfms
265-
266- let defaultProjectInstanceFactory tfmSelector ( projectPath : string ) ( xml : Dictionary < string , string >) ( collection : ProjectCollection ) =
267-
268- let tfm = tfmSelector projectPath
269-
270- let props = Map.union ( Map.ofDict xml) ( Map.ofDict collection.GlobalProperties)
271- // |> Map.mapAddSome "TargetFramework" tfm
266+ |> ProjectPropertyInstance.tryFind " TargetFrameworks"
267+ |> Option.bind ( fun tfms ->
268+ tfms.Split(
269+ ';' ,
270+ StringSplitOptions.TrimEntries
271+ ||| StringSplitOptions.RemoveEmptyEntries
272+ )
273+ |> Option.ofObj
274+ )
275+ )
272276
273- let pi = ProjectInstance( projectPath, props, toolsVersion = null , projectCollection = collection)
277+ let selectFirstTfm ( projectPath : string ) =
278+ getAllTfms projectPath
279+ |> Option.bind Array.tryHead
274280
275- pi
281+ let defaultProjectInstanceFactory ( projectPath : string ) ( xml : Dictionary < string , string >) ( collection : ProjectCollection ) =
282+ let props = Map.union ( Map.ofDict xml) ( Map.ofDict collection.GlobalProperties)
283+ ProjectInstance( projectPath, props, toolsVersion = null , projectCollection = collection)
276284
277285
278286type ProjectLoader2 =
@@ -293,6 +301,30 @@ type ProjectLoader2 =
293301 entryProjectFiles
294302 |> Seq.map ( fun file -> ProjectLoader2.EvaluateAsProject( file, ?globalProperties = globalProperties, ?projectCollection = projectCollection))
295303
304+ static member EvaluateAsProjectsAllTfms ( entryProjectFiles : string seq , ? globalProperties : IDictionary < string , string >, ? projectCollection : ProjectCollection ) =
305+ let globalProperties =
306+ globalProperties
307+ |> Option.map Map.ofDict
308+ |> Option.defaultValue Map.empty
309+
310+ entryProjectFiles
311+ |> Seq.collect ( fun path ->
312+ ProjectLoading.getAllTfms path
313+ |> Option.toArray
314+ |> Array.collect (
315+ Array.map ( fun tfm ->
316+ ProjectLoader2.EvaluateAsProject(
317+ path,
318+ globalProperties =
319+ ( globalProperties
320+ |> Map.add " TargetFramework" tfm
321+ |> Map.copyToDict),
322+ ?projectCollection = projectCollection
323+ )
324+ )
325+ )
326+ )
327+
296328 static member EvaluateAsGraph ( entryProjectFile : string , ? globalProperties : IDictionary < string , string >, ? projectCollection : ProjectCollection , ? projectInstanceFactory , ? ct : CancellationToken ) =
297329 let globalProperties = defaultArg globalProperties null
298330 ProjectLoader2.EvaluateAsGraph([ ProjectGraphEntryPoint( entryProjectFile, globalProperties = globalProperties) ], ?projectCollection = projectCollection, ?projectInstanceFactory = projectInstanceFactory, ?ct = ct)
@@ -301,23 +333,14 @@ type ProjectLoader2 =
301333 let pc = defaultArg projectCollection ProjectCollection.GlobalProjectCollection
302334 let ct = defaultArg ct CancellationToken.None
303335
304- let projectInstanceFactory =
305- defaultArg projectInstanceFactory ( ProjectLoading.defaultProjectInstanceFactory ProjectLoading.selectFirstTfm)
336+ let projectInstanceFactory = defaultArg projectInstanceFactory ProjectLoading.defaultProjectInstanceFactory
306337
307338 ProjectGraph( entryProjectFile, pc, projectInstanceFactory, ct)
308339
309340
310341 static member EvaluateAsGraphAllTfms ( entryProjectFile : ProjectGraphEntryPoint seq , ? projectCollection : ProjectCollection , ? projectInstanceFactory ) =
311-
312- let pc = defaultArg projectCollection ProjectCollection.GlobalProjectCollection
313-
314- let projectInstanceFactory =
315- defaultArg projectInstanceFactory ( ProjectLoading.defaultProjectInstanceFactory ProjectLoading.selectFirstTfm)
316-
317342 let graph =
318- ProjectLoader2.EvaluateAsGraph( entryProjectFile, projectCollection = pc, projectInstanceFactory = projectInstanceFactory)
319-
320- let targets = graph.ProjectNodes
343+ ProjectLoader2.EvaluateAsGraph( entryProjectFile, ?projectCollection = projectCollection, ?projectInstanceFactory = projectInstanceFactory)
321344
322345 let inline tryGetTfmFromProps ( node : ProjectGraphNode ) =
323346 match node.ProjectInstance.GlobalProperties.TryGetValue " TargetFramework" with
@@ -326,7 +349,7 @@ type ProjectLoader2 =
326349
327350 // Then we only care about those with a TargetFramework
328351 let projects =
329- targets
352+ graph.ProjectNodes
330353 |> Seq.choose ( fun node ->
331354 tryGetTfmFromProps node
332355 |> Option.orElseWith ( fun () ->
@@ -336,7 +359,7 @@ type ProjectLoader2 =
336359 |> Option.map ( fun _ -> ProjectGraphEntryPoint( node.ProjectInstance.FullPath, globalProperties = node.ProjectInstance.GlobalProperties))
337360 )
338361
339- ProjectLoader2.EvaluateAsGraph( projects, projectCollection = pc , projectInstanceFactory = projectInstanceFactory)
362+ ProjectLoader2.EvaluateAsGraph( projects, ? projectCollection = projectCollection , ? projectInstanceFactory = projectInstanceFactory)
340363
341364 static member Execution ( session : BuildManagerSession , graph : ProjectGraph , ? targetsToBuild : string array , ? flags : BuildRequestDataFlags , ? ct : CancellationToken ) =
342365 task {
0 commit comments