Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid main thread switch in UpToDateCheckHost #9458

Merged
merged 8 commits into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 23 additions & 20 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -28,39 +28,39 @@
<PackageVersion Include="Microsoft.VisualStudio.Internal.MicroBuild.Vsman" Version="2.0.115" />
<PackageVersion Include="Microsoft.VisualStudioEng.MicroBuild.Core" Version="1.0.0" />
<PackageVersion Include="Nerdbank.GitVersioning" Version="3.6.79-alpha" />
<PackageVersion Include="Nerdbank.Streams" Version="2.10.69" />
<PackageVersion Include="Nerdbank.Streams" Version="2.11.72" />
<PackageVersion Include="System.IO.Pipelines" Version="8.0.0" />

<!-- VS SDK -->
<!-- https://dev.azure.com/azure-public/vside/_artifacts/feed/vssdk -->
<PackageVersion Include="EnvDTE" Version="17.3.32804.24" />
<PackageVersion Include="Microsoft.Internal.VisualStudio.Interop" Version="17.3.32804.24" />
<PackageVersion Include="Microsoft.ServiceHub.Framework" Version="4.3.57" />
<PackageVersion Include="Microsoft.VisualStudio.ComponentModelHost" Version="17.3.198" />
<PackageVersion Include="Microsoft.VisualStudio.Composition" Version="17.7.29" />
<PackageVersion Include="EnvDTE" Version="17.11.38822-preview.1" />
<PackageVersion Include="Microsoft.Internal.VisualStudio.Interop" Version="17.11.38822-preview.1" />
<PackageVersion Include="Microsoft.ServiceHub.Framework" Version="4.5.37" />
<PackageVersion Include="Microsoft.VisualStudio.ComponentModelHost" Version="17.11.111-preview" />
<PackageVersion Include="Microsoft.VisualStudio.Composition" Version="17.10.39" />
<PackageVersion Include="Microsoft.VisualStudio.Data.Core" Version="17.0.0-preview-2-31223-026" />
<PackageVersion Include="Microsoft.VisualStudio.Data.Services" Version="17.0.0-preview-2-31223-026" />
<PackageVersion Include="Microsoft.VisualStudio.DataDesign.Common" Version="17.0.0-preview-2-31223-026" />
<PackageVersion Include="Microsoft.VisualStudio.DataTools.Interop" Version="17.0.0-preview-2-31223-026" />
<PackageVersion Include="Microsoft.VisualStudio.Debugger.Contracts" Version="17.4.0-beta.22470.1" />
<PackageVersion Include="Microsoft.VisualStudio.Debugger.UI.Interfaces" Version="17.4.0-beta.22470.1" />
<PackageVersion Include="Microsoft.VisualStudio.Designer.Interfaces" Version="17.3.32804.24" />
<PackageVersion Include="Microsoft.VisualStudio.ImageCatalog" Version="17.3.32804.24" />
<PackageVersion Include="Microsoft.VisualStudio.Interop" Version="17.4.0-preview-2-32826-307" />
<PackageVersion Include="Microsoft.VisualStudio.Designer.Interfaces" Version="17.11.38822-preview.1" />
<PackageVersion Include="Microsoft.VisualStudio.ImageCatalog" Version="17.11.38822-preview.1" />
<PackageVersion Include="Microsoft.VisualStudio.Interop" Version="17.11.38822-preview.1" />
<PackageVersion Include="Microsoft.VisualStudio.ManagedInterfaces" Version="8.0.50728" />
<PackageVersion Include="Microsoft.VisualStudio.RpcContracts" Version="17.10.3-preview" />
<PackageVersion Include="Microsoft.VisualStudio.Settings.15.0" Version="17.3.32804.24" />
<PackageVersion Include="Microsoft.VisualStudio.RpcContracts" Version="17.11.3-preview" />
<PackageVersion Include="Microsoft.VisualStudio.Settings.15.0" Version="17.11.38822-preview.1" />
<PackageVersion Include="Microsoft.VisualStudio.Setup.Configuration.Interop" Version="3.2.2146" />
<PackageVersion Include="Microsoft.VisualStudio.Shell.15.0" Version="17.3.32804.24" />
<PackageVersion Include="Microsoft.VisualStudio.Shell.Design" Version="17.3.32804.24" />
<PackageVersion Include="Microsoft.VisualStudio.Shell.Framework" Version="17.3.32804.24" />
<PackageVersion Include="Microsoft.VisualStudio.Telemetry" Version="17.8.9" />
<PackageVersion Include="Microsoft.VisualStudio.TemplateWizardInterface" Version="17.3.32804.24" />
<PackageVersion Include="Microsoft.VisualStudio.Threading" Version="17.9.28" />
<PackageVersion Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.9.28" />
<PackageVersion Include="Microsoft.VisualStudio.Utilities" Version="17.7.36307-preview.2" />
<PackageVersion Include="Microsoft.VisualStudio.Shell.15.0" Version="17.11.38822-preview.1" />
<PackageVersion Include="Microsoft.VisualStudio.Shell.Design" Version="17.11.38822-preview.1" />
<PackageVersion Include="Microsoft.VisualStudio.Shell.Framework" Version="17.11.38822-preview.1" />
<PackageVersion Include="Microsoft.VisualStudio.Telemetry" Version="17.11.8" />
<PackageVersion Include="Microsoft.VisualStudio.TemplateWizardInterface" Version="17.11.38822-preview.1" />
<PackageVersion Include="Microsoft.VisualStudio.Threading" Version="17.11.6-preview" />
<PackageVersion Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.11.6-preview" />
<PackageVersion Include="Microsoft.VisualStudio.Utilities" Version="17.11.38822-preview.1" />
<PackageVersion Include="Microsoft.VisualStudio.Validation" Version="17.8.8" />
<PackageVersion Include="Microsoft.VisualStudio.XmlEditor" Version="17.3.32804.24" />
<PackageVersion Include="Microsoft.VisualStudio.XmlEditor" Version="17.11.0-preview-1-34901-010" />
<PackageVersion Include="Microsoft.VSSDK.BuildTools" Version="17.11.54-preview1" />
<PackageVersion Include="System.Threading.Tasks.Dataflow" Version="8.0.0" />
<PackageVersion Include="Microsoft.VSDesigner" Version="17.0.0-preview-2-31223-026" />
Expand Down Expand Up @@ -97,6 +97,9 @@
<!-- Framework packages -->
<PackageVersion Include="Microsoft.IO.Redist" Version="6.0.0" />

<!-- MSBuild (for tests only) -->
<PackageVersion Include="Microsoft.Build" Version="17.11.0-preview-24229-04" />

<!-- Hot Reload -->
<PackageVersion Include="Microsoft.VisualStudio.HotReload.Components" Version="6.0.0-preview.6.21380.4" />

Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -8,54 +10,56 @@ namespace Microsoft.VisualStudio.ProjectSystem.VS.UpToDate
[Export(typeof(IUpToDateCheckHost))]
internal sealed class UpToDateCheckHost : IUpToDateCheckHost
{
private readonly IVsUIService<IVsShell> _vsShell;
private readonly IVsUIService<IVsAppCommandLine> _vsAppCommandLine;
private readonly JoinableTaskContext _joinableTaskContext;

private bool? _hasDesignTimeBuild;
private readonly IVsService<IVsAppId> _vsAppId;
private readonly IVsService<IVsAppCommandLine> _vsAppCommandLine;
private readonly AsyncLazy<bool> _hasDesignTimeBuild;

[ImportingConstructor]
public UpToDateCheckHost(IVsUIService<SVsShell, IVsShell> vsShell, IVsUIService<SVsAppCommandLine, IVsAppCommandLine> vsAppCommandLine, JoinableTaskContext joinableTaskContext)
public UpToDateCheckHost(
IVsService<IVsAppId> vsAppId,
IVsService<SVsAppCommandLine, IVsAppCommandLine> vsAppCommandLine,
JoinableTaskContext joinableTaskContext)
{
_vsShell = vsShell;
_vsAppId = vsAppId;
_vsAppCommandLine = vsAppCommandLine;
_joinableTaskContext = joinableTaskContext;

_hasDesignTimeBuild = new(HasDesignTimeBuildsInternalAsync, joinableTaskContext.Factory);
}

public async ValueTask<bool> HasDesignTimeBuildsAsync(CancellationToken cancellationToken)
{
_hasDesignTimeBuild ??= await ComputeValueAsync();
return await _hasDesignTimeBuild.GetValueAsync(cancellationToken);
}

return _hasDesignTimeBuild.Value;
private async Task<bool> HasDesignTimeBuildsInternalAsync()
{
IVsAppCommandLine vsAppCommandLine = await _vsAppCommandLine.GetValueAsync();

async ValueTask<bool> 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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</ItemGroup>

<ItemGroup>
<Folder Include="ProjectSystem\VS\PackageRestore\Snapshots\" />
<PackageReference Include="Microsoft.Build" />
</ItemGroup>

</Project>
Loading