From fea9bc3b2a996c69c7c98fcee56d5527123b7fb7 Mon Sep 17 00:00:00 2001 From: Drew Noakes Date: Fri, 6 Oct 2023 12:25:05 +1100 Subject: [PATCH] Simplify using non-generic TaskCompletionSource polyfill .NET Core defines a non-generic `System.Threading.Tasks.TaskCompletionSource`. This would be handy in .NET Framework too, so we defined our own version of this as a polyfill. However ours was in the `Microsoft.VisualStudio.Threading.Tasks` namespace. Once we started multi-targeting to .NET Framework and .NET Core, this mismatch created issues. That was worked around with an alias. The approach in this change reduces the friction and improves discoverability of this type. With this, we won't see "ambiguous type" warnings in new code any more. --- .../VS/LanguageServices/LanguageServiceHost.cs | 4 ---- .../ProjectSystem/VS/LanguageServices/Workspace.cs | 4 ---- .../ProjectSystem/VS/VsSolutionEventListener.cs | 1 - .../Build/ImplicitlyActiveConfiguredProjectReadyToBuild.cs | 4 ---- .../ProjectSystem/Debug/LaunchSettingsProvider.cs | 4 ---- .../ProjectSystem/UnconfiguredProjectTasksService.cs | 4 ---- .../Threading/Tasks/TaskCompletionSource.cs | 6 +++++- .../VS/TempPE/DesignTimeInputsChangeTrackerTests.cs | 1 - .../VS/TempPE/DesignTimeInputsCompilerTests.cs | 1 - .../VS/TempPE/DesignTimeInputsFileWatcherTests.cs | 1 - .../ProjectSystem/VS/Utilities/TestUtil.cs | 2 -- 11 files changed, 5 insertions(+), 27 deletions(-) diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/LanguageServices/LanguageServiceHost.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/LanguageServices/LanguageServiceHost.cs index 3dc7be2ab9f..0dafa216e26 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/LanguageServices/LanguageServiceHost.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/LanguageServices/LanguageServiceHost.cs @@ -6,10 +6,6 @@ using Microsoft.VisualStudio.ProjectSystem.Utilities; using Microsoft.VisualStudio.Threading; -// .NET Core defines a non-generic TaskCompletionSource but .NETFramework does not. -// For consistency, always use the one we define. -using TaskCompletionSource = Microsoft.VisualStudio.Threading.Tasks.TaskCompletionSource; - namespace Microsoft.VisualStudio.ProjectSystem.LanguageServices; /// diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/LanguageServices/Workspace.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/LanguageServices/Workspace.cs index e26271f0c6b..b01b2680363 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/LanguageServices/Workspace.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/LanguageServices/Workspace.cs @@ -8,10 +8,6 @@ using Microsoft.VisualStudio.ProjectSystem.Utilities; using Microsoft.VisualStudio.Threading; -// .NET Core defines a non-generic TaskCompletionSource but .NETFramework does not. -// For consistency, always use the one we define. -using TaskCompletionSource = Microsoft.VisualStudio.Threading.Tasks.TaskCompletionSource; - namespace Microsoft.VisualStudio.ProjectSystem.LanguageServices; /// diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/VsSolutionEventListener.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/VsSolutionEventListener.cs index e0a6bb34313..adc8fd6eaab 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/VsSolutionEventListener.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/VsSolutionEventListener.cs @@ -3,7 +3,6 @@ using Microsoft.VisualStudio.ProjectSystem.Properties; using Microsoft.VisualStudio.Shell.Interop; using Microsoft.VisualStudio.Threading; -using Microsoft.VisualStudio.Threading.Tasks; namespace Microsoft.VisualStudio.ProjectSystem.VS { diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Build/ImplicitlyActiveConfiguredProjectReadyToBuild.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Build/ImplicitlyActiveConfiguredProjectReadyToBuild.cs index a3e8de4cd22..bcd905844fa 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Build/ImplicitlyActiveConfiguredProjectReadyToBuild.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Build/ImplicitlyActiveConfiguredProjectReadyToBuild.cs @@ -1,9 +1,5 @@ // Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this file to you under the MIT license. See the LICENSE.md file in the project root for more information. -// .NET Core defines a non-generic TaskCompletionSource but .NETFramework does not. -// For consistency, always use the one we define. -using TaskCompletionSource = Microsoft.VisualStudio.Threading.Tasks.TaskCompletionSource; - namespace Microsoft.VisualStudio.ProjectSystem.Build { [Export(typeof(IConfiguredProjectReadyToBuild))] diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Debug/LaunchSettingsProvider.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Debug/LaunchSettingsProvider.cs index 173e2660eb3..3dafb6083a1 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Debug/LaunchSettingsProvider.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Debug/LaunchSettingsProvider.cs @@ -6,10 +6,6 @@ using Microsoft.VisualStudio.Threading; using Microsoft.VisualStudio.Threading.Tasks; -// .NET Core defines a non-generic TaskCompletionSource but .NETFramework does not. -// For consistency, always use the one we define. -using TaskCompletionSource = Microsoft.VisualStudio.Threading.Tasks.TaskCompletionSource; - namespace Microsoft.VisualStudio.ProjectSystem.Debug { /// diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/UnconfiguredProjectTasksService.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/UnconfiguredProjectTasksService.cs index 32be6e86ed1..d64d5c6bcc7 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/UnconfiguredProjectTasksService.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/UnconfiguredProjectTasksService.cs @@ -2,10 +2,6 @@ using Microsoft.VisualStudio.Threading; -// .NET Core defines a non-generic TaskCompletionSource but .NETFramework does not. -// For consistency, always use the one we define. -using TaskCompletionSource = Microsoft.VisualStudio.Threading.Tasks.TaskCompletionSource; - namespace Microsoft.VisualStudio.ProjectSystem { [Export] diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/Threading/Tasks/TaskCompletionSource.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/Threading/Tasks/TaskCompletionSource.cs index 251629142d8..855980419af 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/Threading/Tasks/TaskCompletionSource.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/Threading/Tasks/TaskCompletionSource.cs @@ -1,8 +1,10 @@ // Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this file to you under the MIT license. See the LICENSE.md file in the project root for more information. +#if NETFRAMEWORK + using System.ComponentModel; -namespace Microsoft.VisualStudio.Threading.Tasks +namespace System.Threading.Tasks { /// /// @@ -54,3 +56,5 @@ public bool TrySetResult() } } } + +#endif diff --git a/tests/Microsoft.VisualStudio.ProjectSystem.Managed.VS.UnitTests/ProjectSystem/VS/TempPE/DesignTimeInputsChangeTrackerTests.cs b/tests/Microsoft.VisualStudio.ProjectSystem.Managed.VS.UnitTests/ProjectSystem/VS/TempPE/DesignTimeInputsChangeTrackerTests.cs index f7f4052fe96..a77e83a0fd8 100644 --- a/tests/Microsoft.VisualStudio.ProjectSystem.Managed.VS.UnitTests/ProjectSystem/VS/TempPE/DesignTimeInputsChangeTrackerTests.cs +++ b/tests/Microsoft.VisualStudio.ProjectSystem.Managed.VS.UnitTests/ProjectSystem/VS/TempPE/DesignTimeInputsChangeTrackerTests.cs @@ -1,6 +1,5 @@ // Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this file to you under the MIT license. See the LICENSE.md file in the project root for more information. -using Microsoft.VisualStudio.Threading.Tasks; using Xunit.Sdk; namespace Microsoft.VisualStudio.ProjectSystem.VS.TempPE diff --git a/tests/Microsoft.VisualStudio.ProjectSystem.Managed.VS.UnitTests/ProjectSystem/VS/TempPE/DesignTimeInputsCompilerTests.cs b/tests/Microsoft.VisualStudio.ProjectSystem.Managed.VS.UnitTests/ProjectSystem/VS/TempPE/DesignTimeInputsCompilerTests.cs index d8203cc6af9..f5a68d9d100 100644 --- a/tests/Microsoft.VisualStudio.ProjectSystem.Managed.VS.UnitTests/ProjectSystem/VS/TempPE/DesignTimeInputsCompilerTests.cs +++ b/tests/Microsoft.VisualStudio.ProjectSystem.Managed.VS.UnitTests/ProjectSystem/VS/TempPE/DesignTimeInputsCompilerTests.cs @@ -4,7 +4,6 @@ using Microsoft.VisualStudio.LanguageServices.ProjectSystem; using Microsoft.VisualStudio.ProjectSystem.LanguageServices; using Microsoft.VisualStudio.Telemetry; -using Microsoft.VisualStudio.Threading.Tasks; using Xunit.Sdk; namespace Microsoft.VisualStudio.ProjectSystem.VS.TempPE diff --git a/tests/Microsoft.VisualStudio.ProjectSystem.Managed.VS.UnitTests/ProjectSystem/VS/TempPE/DesignTimeInputsFileWatcherTests.cs b/tests/Microsoft.VisualStudio.ProjectSystem.Managed.VS.UnitTests/ProjectSystem/VS/TempPE/DesignTimeInputsFileWatcherTests.cs index 31f49f52945..515900c37da 100644 --- a/tests/Microsoft.VisualStudio.ProjectSystem.Managed.VS.UnitTests/ProjectSystem/VS/TempPE/DesignTimeInputsFileWatcherTests.cs +++ b/tests/Microsoft.VisualStudio.ProjectSystem.Managed.VS.UnitTests/ProjectSystem/VS/TempPE/DesignTimeInputsFileWatcherTests.cs @@ -2,7 +2,6 @@ using Microsoft.VisualStudio.Shell; using Microsoft.VisualStudio.Shell.Interop; -using Microsoft.VisualStudio.Threading.Tasks; using Xunit.Sdk; // Nullable annotations don't add a lot of value to this class, and until https://github.com/dotnet/roslyn/issues/33199 is fixed diff --git a/tests/Microsoft.VisualStudio.ProjectSystem.Managed.VS.UnitTests/ProjectSystem/VS/Utilities/TestUtil.cs b/tests/Microsoft.VisualStudio.ProjectSystem.Managed.VS.UnitTests/ProjectSystem/VS/Utilities/TestUtil.cs index 80bfcf6be37..96012a7333f 100644 --- a/tests/Microsoft.VisualStudio.ProjectSystem.Managed.VS.UnitTests/ProjectSystem/VS/Utilities/TestUtil.cs +++ b/tests/Microsoft.VisualStudio.ProjectSystem.Managed.VS.UnitTests/ProjectSystem/VS/Utilities/TestUtil.cs @@ -1,7 +1,5 @@ // Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this file to you under the MIT license. See the LICENSE.md file in the project root for more information. -using Microsoft.VisualStudio.Threading.Tasks; - namespace Microsoft.VisualStudio.ProjectSystem.VS.Utilities { internal static class TestUtil