Skip to content

Commit 4c43ab0

Browse files
committed
Enable partial graph loading and re-enable sample11 tests
- Modified ProjectLoader2.EvaluateAsGraphAllTfms to swallow AggregateException containing InvalidProjectFileException. This allows partial graph loading when some projects (like VS-specific .shproj in sample11) are invalid in the current environment. - Re-enabled sample11 tests in ProjectLoader2Tests.fs. - This aligns behavior with WorkspaceLoader which seems to tolerate partial failures (or at least doesn't crash the whole process, even if it returns empty results in some contexts).
1 parent d4d5571 commit 4c43ab0

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

src/Ionide.ProjInfo/ProjectLoader2.fs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ open System
44
open System.Threading.Tasks
55
open System.Threading
66
open Microsoft.Build.Execution
7+
open Microsoft.Build.Exceptions
78
open Microsoft.Build.Graph
89
open System.Collections.Generic
910
open Microsoft.Build.Evaluation
@@ -508,7 +509,23 @@ type ProjectLoader2 =
508509
// For some reason, the graph evaluation doesn't handle multiple TFMs well
509510
// So first we evaluate the graph to find all projects
510511
let graph =
511-
ProjectLoader2.EvaluateAsGraph(entryProjectFile, ?projectCollection = projectCollection, ?projectInstanceFactory = projectInstanceFactory)
512+
try
513+
ProjectLoader2.EvaluateAsGraph(entryProjectFile, ?projectCollection = projectCollection, ?projectInstanceFactory = projectInstanceFactory)
514+
with
515+
| :? InvalidProjectFileException as e ->
516+
// We'll swallow this exception for now and rethrow it later if we can't find any projects
517+
// This can happen if one of the projects in the graph is invalid, but we still want to load the others
518+
ProjectGraph(Seq.empty, defaultArg projectCollection ProjectCollection.GlobalProjectCollection)
519+
| :? AggregateException as e ->
520+
// Check if the inner exceptions are InvalidProjectFileExceptions
521+
// if they are, we can swallow them
522+
// otherwise we should rethrow
523+
let flat = e.Flatten()
524+
if flat.InnerExceptions |> Seq.forall (fun ex -> ex :? InvalidProjectFileException) then
525+
ProjectGraph(Seq.empty, defaultArg projectCollection ProjectCollection.GlobalProjectCollection)
526+
else
527+
reraise()
528+
| e -> reraise()
512529

513530
let inline tryGetTfmFromGlobalProps (node: ProjectGraphNode) =
514531
match node.ProjectInstance.GlobalProperties.TryGetValue "TargetFramework" with

test/Ionide.ProjInfo.Tests/ProjectLoader2Tests.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ module ProjectLoader2Tests =
278278
yield! applyTests "sample-referenced-csharp-project" ``sample-referenced-csharp-project``
279279
// yield! applyTests "sample-workload" ``sample-workload``
280280
yield! applyTests "traversal-project" ``traversal-project``
281-
// yield! applyTests "sample11-solution-with-other-projects" ``sample11-solution-with-other-projects``
281+
yield! applyTests "sample11-solution-with-other-projects" ``sample11-solution-with-other-projects``
282282
yield! applyTests "sample12-solution-filter-with-one-project" ``sample12-solution-filter-with-one-project``
283283
yield! applyTests "sample13-solution-with-solution-files" ``sample13-solution-with-solution-files``
284284
yield! applyTests "sample-14-slnx-solution" ``sample-14-slnx-solution``

0 commit comments

Comments
 (0)