@@ -78,7 +78,7 @@ module ProjectLoader =
7878 else
7979 [ logger ]
8080
81- let getGlobalProps ( path : string ) ( tfm : string option ) =
81+ let getGlobalProps ( path : string ) ( tfm : string option ) ( globalProperties : ( string * string ) list ) =
8282 dict [ " ProvideCommandLineArgs" , " true"
8383 " DesignTimeBuild" , " true"
8484 " SkipCompilerExecution" , " true"
@@ -91,19 +91,20 @@ module ProjectLoader =
9191 " TargetFramework" , tfm.Value
9292 if path.EndsWith " .csproj" then
9393 " NonExistentFile" , Path.Combine( " __NonExistentSubDir__" , " __NonExistentFile__" )
94- " DotnetProjInfo" , " true" ]
94+ " DotnetProjInfo" , " true"
95+ yield ! globalProperties ]
9596
9697
9798 let buildArgs =
9899 [| " ResolvePackageDependenciesDesignTime"
99100 " _GenerateCompileDependencyCache"
100101 " CoreCompile" |]
101102
102- let loadProject ( path : string ) ( generateBinlog : bool ) ( ToolsPath toolsPath ) =
103+ let loadProject ( path : string ) ( generateBinlog : bool ) ( ToolsPath toolsPath ) globalProperties =
103104 try
104105 let tfm = getTfm path
105106
106- let globalProperties = getGlobalProps path tfm
107+ let globalProperties = getGlobalProps path tfm globalProperties
107108
108109 match System.Environment.GetEnvironmentVariable " DOTNET_HOST_PATH" with
109110 | null
@@ -112,7 +113,7 @@ module ProjectLoader =
112113
113114 use pc = new ProjectCollection( globalProperties)
114115
115- let pi = pc.LoadProject( path)
116+ let pi = pc.LoadProject( path, globalProperties , toolsVersion = null )
116117
117118 use sw = new StringWriter()
118119
@@ -343,10 +344,11 @@ module ProjectLoader =
343344 /// <param name="path">Full path to the `.fsproj` file</param>
344345 /// <param name="toolsPath">Path to MsBuild obtained from `ProjectLoader.init ()`</param>
345346 /// <param name="generateBinlog">Enable Binary Log generation</param>
347+ /// <param name="globalProperties">The global properties to use (e.g. Configuration=Release). Some additional global properties are pre-set by the tool</param>
346348 /// <param name="customProperties">List of additional MsBuild properties that you want to obtain.</param>
347349 /// <returns>Returns the record instance representing the loaded project or string containing error message</returns>
348- let getProjectInfo ( path : string ) ( toolsPath : ToolsPath ) ( generateBinlog : bool ) ( customProperties : string list ) : Result < Types.ProjectOptions , string > =
349- let loadedProject = loadProject path generateBinlog toolsPath
350+ let getProjectInfo ( path : string ) ( toolsPath : ToolsPath ) ( globalProperties : ( string * string ) list ) ( generateBinlog : bool ) ( customProperties : string list ) : Result < Types.ProjectOptions , string > =
351+ let loadedProject = loadProject path generateBinlog toolsPath globalProperties
350352
351353 match loadedProject with
352354 | Success project -> getLoadedProjectInfo path customProperties project
@@ -369,7 +371,8 @@ type IWorkspaceLoader =
369371 [<CLIEvent>]
370372 abstract Notifications : IEvent < WorkspaceProjectState >
371373
372- type WorkspaceLoaderViaProjectGraph private ( toolsPath : ToolsPath ) =
374+ type WorkspaceLoaderViaProjectGraph private ( toolsPath : ToolsPath , ? globalProperties : ( string * string ) list ) =
375+ let globalProperties = defaultArg globalProperties []
373376 let logger = LogProvider.getLoggerFor< WorkspaceLoaderViaProjectGraph> ()
374377 let loadingNotification = new Event< Types.WorkspaceProjectState>()
375378
@@ -383,17 +386,19 @@ type WorkspaceLoaderViaProjectGraph private (toolsPath: ToolsPath) =
383386 loadingNotification.Trigger( WorkspaceProjectState.Failed( p, ProjectNotFound( p)))
384387 None
385388
386- let projectInstanceFactory projectPath globalProperties ( projectCollection : ProjectCollection ) =
389+ let projectInstanceFactory projectPath ( _globalProperties : IDictionary < string , string >) ( projectCollection : ProjectCollection ) =
387390 let tfm = ProjectLoader.getTfm projectPath
388- ProjectInstance( projectPath, ProjectLoader.getGlobalProps projectPath tfm, null , projectCollection)
391+ //let globalProperties = globalProperties |> Seq.toList |> List.map (fun (KeyValue(k,v)) -> (k,v))
392+ let globalProperties = ProjectLoader.getGlobalProps projectPath tfm globalProperties
393+ ProjectInstance( projectPath, globalProperties, toolsVersion= null , projectCollection= projectCollection)
389394
390395 let projectGraphProjs ( paths : string seq ) =
391396
392397 handleProjectGraphFailures
393398 <| fun () ->
394399 paths |> Seq.iter ( fun p -> loadingNotification.Trigger( WorkspaceProjectState.Loading p))
395400 let entryPoints = paths |> Seq.map ProjectGraphEntryPoint
396- ProjectGraph( entryPoints, ProjectCollection.GlobalProjectCollection, projectInstanceFactory)
401+ ProjectGraph( entryPoints, projectCollection = ProjectCollection.GlobalProjectCollection, projectInstanceFactory = projectInstanceFactory)
397402
398403 let projectGraphSln ( path : string ) =
399404 handleProjectGraphFailures
@@ -541,10 +546,11 @@ type WorkspaceLoaderViaProjectGraph private (toolsPath: ToolsPath) =
541546 this.LoadSln( sln, customProperties, false )
542547
543548
544- static member Create ( toolsPath : ToolsPath ) =
545- WorkspaceLoaderViaProjectGraph( toolsPath) :> IWorkspaceLoader
549+ static member Create ( toolsPath : ToolsPath , ? globalProperties ) =
550+ WorkspaceLoaderViaProjectGraph( toolsPath, ?globalProperties = globalProperties ) :> IWorkspaceLoader
546551
547- type WorkspaceLoader private ( toolsPath : ToolsPath ) =
552+ type WorkspaceLoader private ( toolsPath : ToolsPath , ? globalProperties : ( string * string ) list ) =
553+ let globalProperties = defaultArg globalProperties []
548554 let loadingNotification = new Event< Types.WorkspaceProjectState>()
549555
550556
@@ -561,7 +567,7 @@ type WorkspaceLoader private (toolsPath: ToolsPath) =
561567 cache |> Seq.map ( fun n -> n.Value) |> Seq.toList
562568
563569 let rec loadProject p =
564- let res = ProjectLoader.getProjectInfo p toolsPath generateBinlog customProperties
570+ let res = ProjectLoader.getProjectInfo p toolsPath globalProperties generateBinlog customProperties
565571
566572 match res with
567573 | Ok project ->
@@ -644,8 +650,8 @@ type WorkspaceLoader private (toolsPath: ToolsPath) =
644650
645651
646652
647- static member Create ( toolsPath : ToolsPath ) =
648- WorkspaceLoader( toolsPath) :> IWorkspaceLoader
653+ static member Create ( toolsPath : ToolsPath , ? globalProperties ) =
654+ WorkspaceLoader( toolsPath, ?globalProperties = globalProperties ) :> IWorkspaceLoader
649655
650656type ProjectViewerTree =
651657 { Name: string
0 commit comments