Skip to content

Commit 1a2fef2

Browse files
Use ProjectLoader.loadProject + getLoadedProjectInfo instead of WorkspaceLoader
Adopt the simpler lower-level API from Ionide.ProjInfo (as in PR #1055): - Replace WorkspaceLoader.Create + Notifications + LoadProjects with ProjectLoader.loadProject + ProjectLoader.getLoadedProjectInfo - Add explicit Microsoft.Build reference (compile-time only, ExcludeAssets=runtime) since ProjectCollection is now directly instantiated in user code - Fewer lines of code, no async notification subscription needed Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 1234e57 commit 1a2fef2

2 files changed

Lines changed: 12 additions & 24 deletions

File tree

src/fsdocs-tool/ProjectCracker.fs

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -290,32 +290,19 @@ module Crack =
290290
let loggedMessages = System.Collections.Concurrent.ConcurrentQueue<string>()
291291

292292
let result =
293+
// Needs to be done before any ProjectCollection is created
293294
let cwd = System.Environment.CurrentDirectory |> System.IO.DirectoryInfo
294295
let dotnetExe = getDotnetHostPath () |> Option.map System.IO.FileInfo
295-
let toolsPath = Init.init cwd dotnetExe
296-
let loader = WorkspaceLoader.Create(toolsPath, extraMsbuildProperties)
297-
298-
use _ =
299-
loader.Notifications.Subscribe(fun msg ->
300-
match msg with
301-
| WorkspaceProjectState.Failed(_, err) -> loggedMessages.Enqueue(err.ToString())
302-
| _ -> ())
303-
304-
let projects =
305-
loader.LoadProjects([ projectFile ], customProperties, BinaryLogGeneration.Off)
306-
|> Seq.toList
307-
308-
match projects with
309-
| projOptions :: _ -> Ok projOptions
310-
| [] ->
311-
let msgs = loggedMessages.ToArray() |> Array.toList
312-
313-
let errMsg =
314-
match msgs with
315-
| msg :: _ -> msg
316-
| [] -> sprintf "Failed to load project '%s'" projectFile
317-
318-
Error errMsg
296+
let _toolsPath = Init.init cwd dotnetExe
297+
let projectCollection = new Microsoft.Build.Evaluation.ProjectCollection(dict extraMsbuildProperties)
298+
299+
match ProjectLoader.loadProject projectFile BinaryLogGeneration.Off projectCollection with
300+
| Ok loadedProject ->
301+
match ProjectLoader.getLoadedProjectInfo projectFile customProperties loadedProject with
302+
| Ok(ProjectLoader.LoadedProjectInfo.StandardProjectInfo projOptions) -> Ok projOptions
303+
| Ok _ -> Error $"project '%s{projectFile}' is not a standard project"
304+
| Error e -> Error e
305+
| Error e -> Error e
319306

320307
let msgs = (loggedMessages.ToArray() |> Array.toList)
321308

src/fsdocs-tool/fsdocs-tool.fsproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
<PackageReference Include="FSharp.Core" />
5252
<PackageReference Include="CommandLineParser" />
5353
<PackageReference Include="Ionide.ProjInfo" />
54+
<PackageReference Include="Microsoft.Build" IncludeAssets="compile" ExcludeAssets="runtime" PrivateAssets="all" />
5455
<PackageReference Include="Suave" />
5556
</ItemGroup>
5657
</Project>

0 commit comments

Comments
 (0)