diff --git a/Directory.Packages.props b/Directory.Packages.props index 026c8382e8..c9c2159189 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -28,39 +28,39 @@ - + - - - - - + + + + + - - - + + + - - + + - - - - - - - - + + + + + + + + - + @@ -97,6 +97,9 @@ + + + diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/UpToDate/UpToDateCheckHost.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/UpToDate/UpToDateCheckHost.cs index dbed1fd3db..e01ddb9954 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/UpToDate/UpToDateCheckHost.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/UpToDate/UpToDateCheckHost.cs @@ -1,5 +1,7 @@ // 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.Internal.VisualStudio.AppId.Interop; +using Microsoft.VisualStudio.ProjectSystem.VS.Interop; using Microsoft.VisualStudio.Shell.Interop; using Microsoft.VisualStudio.Threading; @@ -8,54 +10,56 @@ namespace Microsoft.VisualStudio.ProjectSystem.VS.UpToDate [Export(typeof(IUpToDateCheckHost))] internal sealed class UpToDateCheckHost : IUpToDateCheckHost { - private readonly IVsUIService _vsShell; - private readonly IVsUIService _vsAppCommandLine; - private readonly JoinableTaskContext _joinableTaskContext; - - private bool? _hasDesignTimeBuild; + private readonly IVsService _vsAppId; + private readonly IVsService _vsAppCommandLine; + private readonly AsyncLazy _hasDesignTimeBuild; [ImportingConstructor] - public UpToDateCheckHost(IVsUIService vsShell, IVsUIService vsAppCommandLine, JoinableTaskContext joinableTaskContext) + public UpToDateCheckHost( + IVsService vsAppId, + IVsService vsAppCommandLine, + JoinableTaskContext joinableTaskContext) { - _vsShell = vsShell; + _vsAppId = vsAppId; _vsAppCommandLine = vsAppCommandLine; - _joinableTaskContext = joinableTaskContext; + + _hasDesignTimeBuild = new(HasDesignTimeBuildsInternalAsync, joinableTaskContext.Factory); } public async ValueTask HasDesignTimeBuildsAsync(CancellationToken cancellationToken) { - _hasDesignTimeBuild ??= await ComputeValueAsync(); + return await _hasDesignTimeBuild.GetValueAsync(cancellationToken); + } - return _hasDesignTimeBuild.Value; + private async Task HasDesignTimeBuildsInternalAsync() + { + IVsAppCommandLine vsAppCommandLine = await _vsAppCommandLine.GetValueAsync(); - async ValueTask ComputeValueAsync() + if (ErrorHandler.Succeeded(vsAppCommandLine.GetOption("populateSolutionCache", out int populateSolutionCachePresent, out string _))) { - await _joinableTaskContext.Factory.SwitchToMainThreadAsync(cancellationToken); - - if (ErrorHandler.Succeeded(_vsAppCommandLine.Value.GetOption("populateSolutionCache", out int populateSolutionCachePresent, out string _))) + if (populateSolutionCachePresent != 0) { - if (populateSolutionCachePresent != 0) - { - // Design time builds are available when running with /populateSolutionCache. - return true; - } + // Design time builds are available when running with /populateSolutionCache. + return true; } + } + + IVsAppId vsAppId = await _vsAppId.GetValueAsync(); - if (ErrorHandler.Succeeded(_vsShell.Value.GetProperty((int)__VSSPROPID.VSSPROPID_IsInCommandLineMode, out object value))) + if (ErrorHandler.Succeeded(vsAppId.GetProperty((int)__VSAPROPID10.VSAPROPID_IsInCommandLineMode, out object value))) + { + if (value is bool isInCommandLineMode) { - if (value is bool isInCommandLineMode) - { - // Design-time builds do not occur in command line mode, other than with /populateSolutionCache (checked earlier). - return !isInCommandLineMode; - } + // Design-time builds do not occur in command line mode, other than with /populateSolutionCache (checked earlier). + return !isInCommandLineMode; } + } - // We shouldn't reach this point. - System.Diagnostics.Debug.Fail($"{nameof(UpToDateCheckHost)}.{nameof(HasDesignTimeBuildsAsync)} was unable to determine result reliably."); + // We shouldn't reach this point. + System.Diagnostics.Debug.Fail($"{nameof(UpToDateCheckHost)}.{nameof(HasDesignTimeBuildsAsync)} was unable to determine result reliably."); - // Assume we don't have design-time builds, to prevent hangs from waiting for snapshot data that will never arrive. - return false; - } + // Assume we don't have design-time builds, to prevent hangs from waiting for snapshot data that will never arrive. + return false; } } } diff --git a/tests/Microsoft.VisualStudio.ProjectSystem.Managed.VS.UnitTests/Microsoft.VisualStudio.ProjectSystem.Managed.VS.UnitTests.csproj b/tests/Microsoft.VisualStudio.ProjectSystem.Managed.VS.UnitTests/Microsoft.VisualStudio.ProjectSystem.Managed.VS.UnitTests.csproj index baaae328ef..18024dc958 100644 --- a/tests/Microsoft.VisualStudio.ProjectSystem.Managed.VS.UnitTests/Microsoft.VisualStudio.ProjectSystem.Managed.VS.UnitTests.csproj +++ b/tests/Microsoft.VisualStudio.ProjectSystem.Managed.VS.UnitTests/Microsoft.VisualStudio.ProjectSystem.Managed.VS.UnitTests.csproj @@ -16,7 +16,7 @@ - + \ No newline at end of file