Skip to content

Commit 8cf52e8

Browse files
committed
Remove obsolete method IActiveConfiguredProjectsProvider.GetActiveConfiguredProjectsMapAsync
1 parent fb1a4ee commit 8cf52e8

File tree

5 files changed

+59
-84
lines changed

5 files changed

+59
-84
lines changed

src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/ActiveConfiguredProjectsProvider.cs

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -63,35 +63,6 @@ public ActiveConfiguredProjectsProvider(IUnconfiguredProjectServices services, U
6363
[ImportMany]
6464
public OrderPrecedenceImportCollection<IActiveConfiguredProjectsDimensionProvider> DimensionProviders { get; }
6565

66-
public async Task<ImmutableDictionary<string, ConfiguredProject>?> GetActiveConfiguredProjectsMapAsync()
67-
{
68-
ActiveConfiguredObjects<ConfiguredProject>? projects = await GetActiveConfiguredProjectsAsync();
69-
70-
if (projects?.Objects.IsEmpty != false)
71-
{
72-
return null;
73-
}
74-
75-
var builder = PooledDictionary<string, ConfiguredProject>.GetInstance();
76-
77-
bool isCrossTargeting = projects.Objects.All(project => project.ProjectConfiguration.IsCrossTargeting());
78-
79-
if (isCrossTargeting)
80-
{
81-
foreach (ConfiguredProject project in projects.Objects)
82-
{
83-
string targetFramework = project.ProjectConfiguration.Dimensions[ConfigurationGeneral.TargetFrameworkProperty];
84-
builder.Add(targetFramework, project);
85-
}
86-
}
87-
else
88-
{
89-
builder.Add(string.Empty, projects.Objects[0]);
90-
}
91-
92-
return builder.ToImmutableDictionaryAndFree();
93-
}
94-
9566
public async Task<ActiveConfiguredObjects<ConfiguredProject>?> GetActiveConfiguredProjectsAsync()
9667
{
9768
ActiveConfiguredObjects<ProjectConfiguration>? configurations = await GetActiveProjectConfigurationsAsync();

src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Debug/ActiveDebugFrameworkServices.cs

Lines changed: 43 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -53,44 +53,67 @@ public async Task SetActiveDebuggingFrameworkPropertyAsync(string activeFramewor
5353

5454
public async Task<ConfiguredProject?> GetConfiguredProjectForActiveFrameworkAsync()
5555
{
56-
#pragma warning disable CS0618 // Type or member is obsolete
57-
ImmutableDictionary<string, ConfiguredProject>? configProjects = await _activeConfiguredProjectsProvider.GetActiveConfiguredProjectsMapAsync();
58-
#pragma warning restore CS0618 // Type or member is obsolete
56+
ActiveConfiguredObjects<ConfiguredProject>? projects = await _activeConfiguredProjectsProvider.GetActiveConfiguredProjectsAsync();
5957

60-
if (configProjects is null)
58+
if (projects is null || projects.Objects.IsEmpty)
6159
{
6260
return null;
6361
}
6462

65-
// If there is only one we are done
66-
if (configProjects.Count == 1)
63+
if (projects.Objects.Length is 1)
6764
{
68-
return configProjects.First().Value;
65+
return projects.Objects[0];
6966
}
7067

71-
string? activeFramework = await GetActiveDebuggingFrameworkPropertyAsync();
68+
bool isMultiTargeting = projects.Objects.All(project => project.ProjectConfiguration.IsCrossTargeting());
7269

73-
if (!Strings.IsNullOrWhiteSpace(activeFramework))
70+
if (isMultiTargeting)
7471
{
75-
if (configProjects.TryGetValue(activeFramework, out ConfiguredProject? configuredProject))
72+
string? activeDebugFramework = await GetActiveDebuggingFrameworkPropertyAsync();
73+
74+
ConfiguredProject? project = FindProject(activeDebugFramework);
75+
76+
if (project is null)
7677
{
77-
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+
}
7886
}
87+
88+
System.Diagnostics.Debug.Assert(project is not null, "Unable to determine debug project configuration.");
89+
90+
return project;
7991
}
92+
else
93+
{
94+
System.Diagnostics.Debug.Assert(projects.Objects.Length == 1, "Expected only one active configured project when not cross-targeting.");
8095

81-
// We can't just select the first one. If activeFramework is not set we must pick the first one as defined by the
82-
// targetFrameworks property. So we need the order as returned by GetProjectFrameworks()
83-
List<string>? frameworks = await GetProjectFrameworksAsync();
96+
return projects.Objects[0];
97+
}
8498

85-
if (frameworks?.Count > 0)
99+
ConfiguredProject? FindProject(string? targetFramework)
86100
{
87-
if (configProjects.TryGetValue(frameworks[0], out ConfiguredProject? configuredProject))
101+
if (Strings.IsNullOrWhiteSpace(targetFramework))
88102
{
89-
return configuredProject;
103+
return null;
90104
}
91-
}
92105

93-
// All that is left is to return the first one.
94-
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+
}
95118
}
96119
}

src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/IActiveConfiguredProjectsProvider.cs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,6 @@ namespace Microsoft.VisualStudio.ProjectSystem;
1414
[ProjectSystemContract(ProjectSystemContractScope.UnconfiguredProject, ProjectSystemContractProvider.Private, Cardinality = ImportCardinality.ExactlyOne)]
1515
internal interface IActiveConfiguredProjectsProvider
1616
{
17-
/// <summary>
18-
/// Gets all the active configured projects by TargetFramework dimension for the current unconfigured project.
19-
/// If the current project is not a cross-targeting project, then it returns a singleton key-value pair with an
20-
/// ignorable key and single active configured project as value.
21-
/// </summary>
22-
/// <returns>
23-
/// Map from TargetFramework dimension to active configured project, or <see langword="null" /> if there
24-
/// are no active <see cref="ConfiguredProject"/> objects.
25-
/// </returns>
26-
[Obsolete("This method will be removed in a future build.")]
27-
Task<ImmutableDictionary<string, ConfiguredProject>?> GetActiveConfiguredProjectsMapAsync();
28-
2917
/// <summary>
3018
/// Returns the ordered list of configured projects that are active for the current project, loading them if needed.
3119
/// </summary>

tests/Microsoft.VisualStudio.ProjectSystem.Managed.UnitTests/Mocks/IActiveConfiguredProjectsProviderFactory.cs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,6 @@ public void Verify()
1313
_mock.Verify();
1414
}
1515

16-
public IActiveConfiguredProjectsProviderFactory ImplementGetActiveConfiguredProjectsMapAsync(ImmutableDictionary<string, ConfiguredProject> configuredProjects)
17-
{
18-
#pragma warning disable CS0618 // Type or member is obsolete
19-
_mock.Setup(x => x.GetActiveConfiguredProjectsMapAsync())
20-
#pragma warning restore CS0618 // Type or member is obsolete
21-
.ReturnsAsync(configuredProjects);
22-
return this;
23-
}
24-
2516
public IActiveConfiguredProjectsProviderFactory ImplementGetActiveConfiguredProjectsAsync(ActiveConfiguredObjects<ConfiguredProject> configuredProjects)
2617
{
2718
_mock.Setup(x => x.GetActiveConfiguredProjectsAsync())

tests/Microsoft.VisualStudio.ProjectSystem.Managed.UnitTests/ProjectSystem/Debug/ActiveDebugFrameworkServicesTests.cs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -74,23 +74,25 @@ public async Task GetConfiguredProjectForActiveFrameworkAsync_ReturnsCorrectProj
7474
var data = new PropertyPageData(ProjectDebugger.SchemaName, ProjectDebugger.ActiveDebugFrameworkProperty, framework);
7575
var data2 = new PropertyPageData(ConfigurationGeneral.SchemaName, ConfigurationGeneral.TargetFrameworksProperty, "net462;net461;netcoreapp1.0");
7676

77-
var projects = ImmutableStringDictionary<ConfiguredProject>.EmptyOrdinal
78-
.Add("net461", ConfiguredProjectFactory.Create(null, new StandardProjectConfiguration("Debug|AnyCPU|net461", Empty.PropertiesMap
79-
.Add("Configuration", "Debug")
80-
.Add("Platform", "AnyCPU")
81-
.Add("TargetFramework", "net461"))))
82-
.Add("netcoreapp1.0", ConfiguredProjectFactory.Create(null, new StandardProjectConfiguration("Debug|AnyCPU|netcoreapp1.0", Empty.PropertiesMap
83-
.Add("Configuration", "Debug")
84-
.Add("Platform", "AnyCPU")
85-
.Add("TargetFramework", "netcoreapp1.0"))))
86-
.Add("net462", ConfiguredProjectFactory.Create(null, new StandardProjectConfiguration("Debug|AnyCPU|net462", Empty.PropertiesMap
87-
.Add("Configuration", "Debug")
88-
.Add("Platform", "AnyCPU")
89-
.Add("TargetFramework", "net462"))));
77+
ImmutableArray<ConfiguredProject> projects =
78+
[
79+
ConfiguredProjectFactory.Create(null, new StandardProjectConfiguration("Debug|AnyCPU|net461", Empty.PropertiesMap
80+
.Add("Configuration", "Debug")
81+
.Add("Platform", "AnyCPU")
82+
.Add("TargetFramework", "net461"))),
83+
ConfiguredProjectFactory.Create(null, new StandardProjectConfiguration("Debug|AnyCPU|netcoreapp1.0", Empty.PropertiesMap
84+
.Add("Configuration", "Debug")
85+
.Add("Platform", "AnyCPU")
86+
.Add("TargetFramework", "netcoreapp1.0"))),
87+
ConfiguredProjectFactory.Create(null, new StandardProjectConfiguration("Debug|AnyCPU|net462", Empty.PropertiesMap
88+
.Add("Configuration", "Debug")
89+
.Add("Platform", "AnyCPU")
90+
.Add("TargetFramework", "net462")))
91+
];
9092

9193
var projectProperties = ProjectPropertiesFactory.Create(project, data, data2);
9294
var projectConfigProvider = new IActiveConfiguredProjectsProviderFactory(MockBehavior.Strict)
93-
.ImplementGetActiveConfiguredProjectsMapAsync(projects);
95+
.ImplementGetActiveConfiguredProjectsAsync(new ActiveConfiguredObjects<ConfiguredProject>(projects, ["TargetFramework"]));
9496

9597
var commonServices = IUnconfiguredProjectCommonServicesFactory.Create(projectProperties: projectProperties);
9698

0 commit comments

Comments
 (0)