Skip to content

Commit d105e06

Browse files
authored
Merge pull request #9724 from drewnoakes/remove-obsolete-code
Remove obsolete code
2 parents cd8b30d + 8cf52e8 commit d105e06

File tree

6 files changed

+67
-108
lines changed

6 files changed

+67
-108
lines changed

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

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ namespace Microsoft.VisualStudio.ProjectSystem;
88
[Export(typeof(IActiveConfiguredProjectsProvider))]
99
internal class ActiveConfiguredProjectsProvider : IActiveConfiguredProjectsProvider
1010
{
11-
// A project configuration is considered active if its dimensions matches the active solution configuration skipping
12-
// any ignored dimensions names (provided by IActiveConfiguredProjectsDimensionProvider instances):
11+
// A project configuration is considered active if its dimensions match the active solution configuration, skipping
12+
// any ignored dimensions names (provided by IActiveConfiguredProjectsDimensionProvider instances).
1313
//
1414
// For example, given the following cross-targeting project:
1515
//
@@ -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: 46 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ public ActiveDebugFrameworkServices(IActiveConfiguredProjectsProvider activeConf
2121
_commonProjectServices = commonProjectServices;
2222
}
2323

24-
/// <summary>
25-
/// <see cref="IActiveDebugFrameworkServices.GetProjectFrameworksAsync"/>
26-
/// </summary>
2724
public async Task<List<string>?> GetProjectFrameworksAsync()
2825
{
2926
// 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
4037
return BuildUtilities.GetPropertyValues(targetFrameworks).ToList();
4138
}
4239

43-
/// <summary>
44-
/// <see cref="IActiveDebugFrameworkServices.SetActiveDebuggingFrameworkPropertyAsync"/>
45-
/// </summary>
4640
public async Task SetActiveDebuggingFrameworkPropertyAsync(string activeFramework)
4741
{
4842
ProjectDebugger props = await _commonProjectServices.ActiveConfiguredProjectProperties.GetProjectDebuggerPropertiesAsync();
43+
4944
await props.ActiveDebugFramework.SetValueAsync(activeFramework);
5045
}
5146

52-
/// <summary>
53-
/// <see cref="IActiveDebugFrameworkServices.GetActiveDebuggingFrameworkPropertyAsync"/>
54-
/// </summary>
5547
public async Task<string?> GetActiveDebuggingFrameworkPropertyAsync()
5648
{
5749
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;
6052
}
6153

62-
/// <summary>
63-
/// <see cref="IActiveDebugFrameworkServices.GetConfiguredProjectForActiveFrameworkAsync"/>
64-
/// </summary>
6554
public async Task<ConfiguredProject?> GetConfiguredProjectForActiveFrameworkAsync()
6655
{
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();
7057

71-
if (configProjects is null)
58+
if (projects is null || projects.Objects.IsEmpty)
7259
{
7360
return null;
7461
}
7562

76-
// If there is only one we are done
77-
if (configProjects.Count == 1)
63+
if (projects.Objects.Length is 1)
7864
{
79-
return configProjects.First().Value;
65+
return projects.Objects[0];
8066
}
8167

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

84-
if (!Strings.IsNullOrWhiteSpace(activeFramework))
70+
if (isMultiTargeting)
8571
{
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)
8777
{
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+
}
8986
}
87+
88+
System.Diagnostics.Debug.Assert(project is not null, "Unable to determine debug project configuration.");
89+
90+
return project;
9091
}
92+
else
93+
{
94+
System.Diagnostics.Debug.Assert(projects.Objects.Length == 1, "Expected only one active configured project when not cross-targeting.");
9195

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+
}
9598

96-
if (frameworks?.Count > 0)
99+
ConfiguredProject? FindProject(string? targetFramework)
97100
{
98-
if (configProjects.TryGetValue(frameworks[0], out ConfiguredProject? configuredProject))
101+
if (Strings.IsNullOrWhiteSpace(targetFramework))
99102
{
100-
return configuredProject;
103+
return null;
101104
}
102-
}
103105

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+
}
106118
}
107119
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public interface IActiveDebugFrameworkServices
2525
Task<string?> GetActiveDebuggingFrameworkPropertyAsync();
2626

2727
/// <summary>
28-
/// Returns the configured project which represents the active framework. This is valid whether multi-targeting or not.
28+
/// Returns the configured project that corresponds with the active debugging framework. This is valid whether multi-targeting or not.
2929
/// </summary>
3030
Task<ConfiguredProject?> GetConfiguredProjectForActiveFrameworkAsync();
3131
}

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: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,9 @@
22

33
namespace Microsoft.VisualStudio.ProjectSystem.Debug;
44

5-
internal class IActiveConfiguredProjectsProviderFactory
5+
internal class IActiveConfiguredProjectsProviderFactory(MockBehavior mockBehavior = MockBehavior.Strict)
66
{
7-
private readonly Mock<IActiveConfiguredProjectsProvider> _mock;
8-
9-
public IActiveConfiguredProjectsProviderFactory(MockBehavior mockBehavior = MockBehavior.Strict)
10-
{
11-
_mock = new Mock<IActiveConfiguredProjectsProvider>(mockBehavior);
12-
}
7+
private readonly Mock<IActiveConfiguredProjectsProvider> _mock = new(mockBehavior);
138

149
public IActiveConfiguredProjectsProvider Object => _mock.Object;
1510

@@ -18,15 +13,6 @@ public void Verify()
1813
_mock.Verify();
1914
}
2015

21-
public IActiveConfiguredProjectsProviderFactory ImplementGetActiveConfiguredProjectsMapAsync(ImmutableDictionary<string, ConfiguredProject> configuredProjects)
22-
{
23-
#pragma warning disable CS0618 // Type or member is obsolete
24-
_mock.Setup(x => x.GetActiveConfiguredProjectsMapAsync())
25-
#pragma warning restore CS0618 // Type or member is obsolete
26-
.ReturnsAsync(configuredProjects);
27-
return this;
28-
}
29-
3016
public IActiveConfiguredProjectsProviderFactory ImplementGetActiveConfiguredProjectsAsync(ActiveConfiguredObjects<ConfiguredProject> configuredProjects)
3117
{
3218
_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)