@@ -21,9 +21,6 @@ public ActiveDebugFrameworkServices(IActiveConfiguredProjectsProvider activeConf
21
21
_commonProjectServices = commonProjectServices ;
22
22
}
23
23
24
- /// <summary>
25
- /// <see cref="IActiveDebugFrameworkServices.GetProjectFrameworksAsync"/>
26
- /// </summary>
27
24
public async Task < List < string > ? > GetProjectFrameworksAsync ( )
28
25
{
29
26
// It is important that we return the frameworks in the order they are specified in the project to ensure the default is set
@@ -40,68 +37,83 @@ public ActiveDebugFrameworkServices(IActiveConfiguredProjectsProvider activeConf
40
37
return BuildUtilities . GetPropertyValues ( targetFrameworks ) . ToList ( ) ;
41
38
}
42
39
43
- /// <summary>
44
- /// <see cref="IActiveDebugFrameworkServices.SetActiveDebuggingFrameworkPropertyAsync"/>
45
- /// </summary>
46
40
public async Task SetActiveDebuggingFrameworkPropertyAsync ( string activeFramework )
47
41
{
48
42
ProjectDebugger props = await _commonProjectServices . ActiveConfiguredProjectProperties . GetProjectDebuggerPropertiesAsync ( ) ;
43
+
49
44
await props . ActiveDebugFramework . SetValueAsync ( activeFramework ) ;
50
45
}
51
46
52
- /// <summary>
53
- /// <see cref="IActiveDebugFrameworkServices.GetActiveDebuggingFrameworkPropertyAsync"/>
54
- /// </summary>
55
47
public async Task < string ? > GetActiveDebuggingFrameworkPropertyAsync ( )
56
48
{
57
49
ProjectDebugger props = await _commonProjectServices . ActiveConfiguredProjectProperties . GetProjectDebuggerPropertiesAsync ( ) ;
58
- string ? activeValue = await props . ActiveDebugFramework . GetValueAsync ( ) as string ;
59
- return activeValue ;
50
+
51
+ return await props . ActiveDebugFramework . GetValueAsync ( ) as string ;
60
52
}
61
53
62
- /// <summary>
63
- /// <see cref="IActiveDebugFrameworkServices.GetConfiguredProjectForActiveFrameworkAsync"/>
64
- /// </summary>
65
54
public async Task < ConfiguredProject ? > GetConfiguredProjectForActiveFrameworkAsync ( )
66
55
{
67
- #pragma warning disable CS0618 // Type or member is obsolete
68
- ImmutableDictionary < string , ConfiguredProject > ? configProjects = await _activeConfiguredProjectsProvider . GetActiveConfiguredProjectsMapAsync ( ) ;
69
- #pragma warning restore CS0618 // Type or member is obsolete
56
+ ActiveConfiguredObjects < ConfiguredProject > ? projects = await _activeConfiguredProjectsProvider . GetActiveConfiguredProjectsAsync ( ) ;
70
57
71
- if ( configProjects is null )
58
+ if ( projects is null || projects . Objects . IsEmpty )
72
59
{
73
60
return null ;
74
61
}
75
62
76
- // If there is only one we are done
77
- if ( configProjects . Count == 1 )
63
+ if ( projects . Objects . Length is 1 )
78
64
{
79
- return configProjects . First ( ) . Value ;
65
+ return projects . Objects [ 0 ] ;
80
66
}
81
67
82
- string ? activeFramework = await GetActiveDebuggingFrameworkPropertyAsync ( ) ;
68
+ bool isMultiTargeting = projects . Objects . All ( project => project . ProjectConfiguration . IsCrossTargeting ( ) ) ;
83
69
84
- if ( ! Strings . IsNullOrWhiteSpace ( activeFramework ) )
70
+ if ( isMultiTargeting )
85
71
{
86
- if ( configProjects . TryGetValue ( activeFramework , out ConfiguredProject ? configuredProject ) )
72
+ string ? activeDebugFramework = await GetActiveDebuggingFrameworkPropertyAsync ( ) ;
73
+
74
+ ConfiguredProject ? project = FindProject ( activeDebugFramework ) ;
75
+
76
+ if ( project is null )
87
77
{
88
- return configuredProject ;
78
+ // The expected debug framework was not found, so we need to pick one.
79
+ // Use the first target as defined in the TargetFrameworks property. This is treated specially.
80
+ // We must pick the first that was defined can't just select the first one. If activeFramework is not set we must pick the first one as defined by the
81
+ // targetFrameworks property. So we need the order as returned by GetProjectFrameworks()
82
+ if ( await GetProjectFrameworksAsync ( ) is [ string firstFramework , ..] )
83
+ {
84
+ project = FindProject ( firstFramework ) ;
85
+ }
89
86
}
87
+
88
+ System . Diagnostics . Debug . Assert ( project is not null , "Unable to determine debug project configuration." ) ;
89
+
90
+ return project ;
90
91
}
92
+ else
93
+ {
94
+ System . Diagnostics . Debug . Assert ( projects . Objects . Length == 1 , "Expected only one active configured project when not cross-targeting." ) ;
91
95
92
- // We can't just select the first one. If activeFramework is not set we must pick the first one as defined by the
93
- // targetFrameworks property. So we need the order as returned by GetProjectFrameworks()
94
- List < string > ? frameworks = await GetProjectFrameworksAsync ( ) ;
96
+ return projects . Objects [ 0 ] ;
97
+ }
95
98
96
- if ( frameworks ? . Count > 0 )
99
+ ConfiguredProject ? FindProject ( string ? targetFramework )
97
100
{
98
- if ( configProjects . TryGetValue ( frameworks [ 0 ] , out ConfiguredProject ? configuredProject ) )
101
+ if ( Strings . IsNullOrWhiteSpace ( targetFramework ) )
99
102
{
100
- return configuredProject ;
103
+ return null ;
101
104
}
102
- }
103
105
104
- // All that is left is to return the first one.
105
- return configProjects . First ( ) . Value ;
106
+ foreach ( ConfiguredProject project in projects . Objects )
107
+ {
108
+ string tf = project . ProjectConfiguration . Dimensions [ ConfigurationGeneral . TargetFrameworkProperty ] ;
109
+
110
+ if ( StringComparers . ConfigurationDimensionValues . Equals ( tf , targetFramework ) )
111
+ {
112
+ return project ;
113
+ }
114
+ }
115
+
116
+ return null ;
117
+ }
106
118
}
107
119
}
0 commit comments