Skip to content

Commit

Permalink
Merge pull request #9561 from harleend/dev/hadhaliw/ExportInitialRule…
Browse files Browse the repository at this point in the history
…sSubscriptions

Export initial rules subscriptions
  • Loading branch information
drewnoakes authored Oct 24, 2024
2 parents 994da35 + d012bf9 commit 267e898
Show file tree
Hide file tree
Showing 15 changed files with 92 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ namespace Microsoft.VisualStudio.ProjectSystem.VS.Frameworks
/// </summary>
[ExportDynamicEnumValuesProvider("SupportedTargetFrameworkAliasEnumProvider")]
[AppliesTo(ProjectCapability.DotNet)]
[ExportInitialBuildRulesSubscriptions(SupportedTargetFrameworkAlias.SchemaName)]
internal class SupportedTargetFrameworkAliasEnumProvider : ChainedProjectValueDataSourceBase<EnumCollection>, IDynamicEnumValuesProvider, IDynamicEnumValuesGenerator
{
private readonly IProjectSubscriptionService _subscriptionService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ namespace Microsoft.VisualStudio.ProjectSystem.LanguageServices;
/// </remarks>
[Export(typeof(IWorkspaceWriter))]
[Export(ExportContractNames.Scopes.UnconfiguredProject, typeof(IProjectDynamicLoadComponent))]
[ExportInitialBuildRulesSubscriptions(CompilerCommandLineArgs.SchemaName)]
[AppliesTo(ProjectCapability.DotNetLanguageService)]
internal sealed class LanguageServiceHost : OnceInitializedOnceDisposedAsync, IProjectDynamicLoadComponent, IWorkspaceWriter
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ internal enum WorkspaceState
Disposed
}

private const string ProjectBuildRuleName = CompilerCommandLineArgs.SchemaName;

private readonly DisposableBag _disposableBag;

private readonly ProjectConfigurationSlice _slice;
Expand Down Expand Up @@ -418,7 +416,7 @@ private async Task OnBuildUpdateAsync(IProjectVersionedValue<BuildUpdate> update
await OnProjectChangedAsync(
_buildProgressRegistration,
update,
hasChange: e => e.Value.BuildRuleUpdate.ProjectChanges[ProjectBuildRuleName].Difference.AnyChanges,
hasChange: e => e.Value.BuildRuleUpdate.ProjectChanges[CompilerCommandLineArgs.SchemaName].Difference.AnyChanges,
applyFunc: ApplyProjectBuild,
_unloadCancellationToken);

Expand All @@ -429,7 +427,7 @@ void ApplyProjectBuild(
ContextState state,
CancellationToken cancellationToken)
{
IProjectChangeDescription projectChange = update.Value.BuildRuleUpdate.ProjectChanges[ProjectBuildRuleName];
IProjectChangeDescription projectChange = update.Value.BuildRuleUpdate.ProjectChanges[CompilerCommandLineArgs.SchemaName];

ProcessCommandLine();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ namespace Microsoft.VisualStudio.ProjectSystem.LanguageServices;
[Export(typeof(IWorkspaceFactory))]
internal class WorkspaceFactory : IWorkspaceFactory
{
private const string ProjectBuildRuleName = CompilerCommandLineArgs.SchemaName;

private readonly UnconfiguredProject _unconfiguredProject;
private readonly IProjectService _projectService;
private readonly IProjectThreadingService _threadingService;
Expand Down Expand Up @@ -142,7 +140,7 @@ var buildTransformBlock
{
ProjectDataSources.SyncLinkTo(
source.ActiveConfiguredProjectSource.SourceBlock.SyncLinkOptions(),
source.ProjectBuildRuleSource.SourceBlock.SyncLinkOptions(DataflowOption.WithRuleNames(ProjectBuildRuleName)),
source.ProjectBuildRuleSource.SourceBlock.SyncLinkOptions(DataflowOption.WithRuleNames(CompilerCommandLineArgs.SchemaName)),
target: buildTransformBlock,
linkOptions: DataflowOption.PropagateCompletion,
cancellationToken: cancellationToken),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ namespace Microsoft.VisualStudio.ProjectSystem.VS.Setup;
/// </remarks>
[Export(ExportContractNames.Scopes.UnconfiguredProject, typeof(IProjectDynamicLoadComponent))]
[AppliesTo(ProjectCapability.DotNet)]
[ExportInitialBuildRulesSubscriptions(SuggestedWorkload.SchemaName)]
internal sealed class SetupComponentProvider : OnceInitializedOnceDisposedAsync, IProjectDynamicLoadComponent
{
private readonly UnconfiguredProject _unconfiguredProject;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// 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.ProjectSystem.Tree.Dependencies.Subscriptions.MSBuildDependencies;

namespace Microsoft.VisualStudio.ProjectSystem.VS.Tree.Dependencies;

/// <summary>
/// Exports the set of rules required for the dependencies tree in Visual Studio.
/// </summary>
/// <remarks>
/// The dependencies tree handles this metadata a little differently to other components in the project system that export it.
/// The dependencies tree works a little differently between VS and VS Code.
/// <list type="bullet">
/// <item>In VS (which loads this assembly) the dependencies tree is loaded eagerly. We want the targets referenced by these rules to be included in the first design-time build.</item>
/// <item>In VS Code (which uses the shared layer) the tree is loaded lazily, and we don't want these targets included in the first design-time build.</item>
/// </list>
/// For this reason, we export the rules here in the VS-only layer, rather than in the shared layer (like other components).
/// </remarks>
internal static class DependenciesTreeBuildRuleRequirements
{
[AppliesTo(AnalyzerDependencyFactory.AppliesTo)]
[ExportInitialBuildRulesSubscriptions(ResolvedAnalyzerReference.SchemaName)]
public static int AnalyzerReference;

[AppliesTo(AssemblyDependencyFactory.AppliesTo)]
[ExportInitialBuildRulesSubscriptions(ResolvedAssemblyReference.SchemaName)]
public static int AssemblyReference;

[AppliesTo(ComDependencyFactory.AppliesTo)]
[ExportInitialBuildRulesSubscriptions(ResolvedCOMReference.SchemaName)]
public static int ComReference;

[AppliesTo(FrameworkDependencyFactory.AppliesTo)]
[ExportInitialBuildRulesSubscriptions(ResolvedFrameworkReference.SchemaName)]
public static int FrameworkReference;

[AppliesTo(PackageDependencyFactory.AppliesTo)]
[ExportInitialBuildRulesSubscriptions(ResolvedPackageReference.SchemaName)]
public static int PackageReference;

[AppliesTo(ProjectDependencyFactory.AppliesTo)]
[ExportInitialBuildRulesSubscriptions(ResolvedProjectReference.SchemaName)]
public static int ProjectReference;

[AppliesTo(SdkDependencyFactory.AppliesTo)]
[ExportInitialBuildRulesSubscriptions(ResolvedSdkReference.SchemaName)]
public static int SdkReference;
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ namespace Microsoft.VisualStudio.ProjectSystem.VS.UpToDate
/// <inheritdoc cref="IUpToDateCheckImplicitConfiguredInputDataSource" />
[Export(typeof(IUpToDateCheckImplicitConfiguredInputDataSource))]
[AppliesTo(BuildUpToDateCheck.AppliesToExpression)]
[ExportInitialBuildRulesSubscriptions([
ResolvedAnalyzerReference.SchemaName,
ResolvedCompilationReference.SchemaName,
ResolvedProjectReference.SchemaName,
UpToDateCheckInput.SchemaName,
UpToDateCheckOutput.SchemaName,
UpToDateCheckBuilt.SchemaName,
CopyToOutputDirectoryItem.SchemaName,
BuildAccelerationIncompatiblePackage.SchemaName])]
internal sealed class UpToDateCheckImplicitConfiguredInputDataSource : ChainedProjectValueDataSourceBase<UpToDateCheckImplicitConfiguredInput>, IUpToDateCheckImplicitConfiguredInputDataSource
{
private readonly ConfiguredProject _configuredProject;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ namespace Microsoft.VisualStudio.ProjectSystem.PackageRestore
/// </summary>
[Export(typeof(IPackageRestoreConfiguredInputDataSource))]
[AppliesTo(ProjectCapability.PackageReferences)]
[ExportInitialBuildRulesSubscriptions([
CollectedFrameworkReference.SchemaName,
CollectedPackageDownload.SchemaName,
CollectedPackageVersion.SchemaName,
CollectedNuGetAuditSuppressions.SchemaName,
CollectedPackageReference.SchemaName])]
internal class PackageRestoreConfiguredInputDataSource : ChainedProjectValueDataSourceBase<PackageRestoreConfiguredInput>, IPackageRestoreConfiguredInputDataSource
{
private static readonly ImmutableHashSet<string> s_rules = Empty.OrdinalIgnoreCaseStringSet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
namespace Microsoft.VisualStudio.ProjectSystem.Tree.Dependencies.Subscriptions.MSBuildDependencies;

[Export(typeof(IMSBuildDependencyFactory))]
// There's no "AnalyzerReferences" capability, and F# doesn't have analyzers
[AppliesTo(ProjectCapability.DependenciesTree + " & (" + ProjectCapability.CSharp + " | " + ProjectCapability.VisualBasic + ")")]
[AppliesTo(AppliesTo)]
internal sealed class AnalyzerDependencyFactory : MSBuildDependencyFactoryBase
{
// There's no "AnalyzerReferences" capability, and F# doesn't have analyzers
public const string AppliesTo = ProjectCapability.DependenciesTree + " & (" + ProjectCapability.CSharp + " | " + ProjectCapability.VisualBasic + ")";

// NOTE we include ProjectTreeFlags.FileSystemEntity here so that Roslyn can correctly identify the
// analyzer's path in order to attach child nodes to these dependency items in Solution Explorer.
// Without this flag, CPS will remove whatever file path we pass during tree construction (for
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
namespace Microsoft.VisualStudio.ProjectSystem.Tree.Dependencies.Subscriptions.MSBuildDependencies;

[Export(typeof(IMSBuildDependencyFactory))]
[AppliesTo(ProjectCapability.DependenciesTree + " & (" + ProjectCapabilities.AssemblyReferences + " | " + ProjectCapabilities.WinRTReferences + ")")]
[AppliesTo(AppliesTo)]
internal sealed class AssemblyDependencyFactory : MSBuildDependencyFactoryBase
{
public const string AppliesTo = ProjectCapability.DependenciesTree + " & (" + ProjectCapabilities.AssemblyReferences + " | " + ProjectCapabilities.WinRTReferences + ")";

private static readonly DependencyFlagCache s_flagCache = new(
resolved: DependencyTreeFlags.AssemblyDependency + DependencyTreeFlags.SupportsBrowse,
unresolved: DependencyTreeFlags.AssemblyDependency);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
namespace Microsoft.VisualStudio.ProjectSystem.Tree.Dependencies.Subscriptions.MSBuildDependencies;

[Export(typeof(IMSBuildDependencyFactory))]
[AppliesTo(ProjectCapability.DependenciesTree + " & " + ProjectCapabilities.ComReferences)]
[AppliesTo(AppliesTo)]
internal sealed class ComDependencyFactory : MSBuildDependencyFactoryBase
{
public const string AppliesTo = ProjectCapability.DependenciesTree + " & " + ProjectCapabilities.ComReferences;

private static readonly DependencyFlagCache s_flagCache = new(
resolved: DependencyTreeFlags.ComDependency + DependencyTreeFlags.SupportsBrowse,
unresolved: DependencyTreeFlags.ComDependency);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
namespace Microsoft.VisualStudio.ProjectSystem.Tree.Dependencies.Subscriptions.MSBuildDependencies;

[Export(typeof(IMSBuildDependencyFactory))]
[AppliesTo(ProjectCapability.DependenciesTree + " & " + ProjectCapability.DotNet)] // There's no "FrameworkReferences" capability
[AppliesTo(AppliesTo)]
internal sealed class FrameworkDependencyFactory : MSBuildDependencyFactoryBase
{
// There's no "FrameworkReferences" capability
public const string AppliesTo = ProjectCapability.DependenciesTree + " & " + ProjectCapability.DotNet;

// Framework references were introduced in .NET Core 2.0

private static readonly DependencyFlagCache s_flagCache = new(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
namespace Microsoft.VisualStudio.ProjectSystem.Tree.Dependencies.Subscriptions.MSBuildDependencies
{
[Export(typeof(IMSBuildDependencyFactory))]
[AppliesTo(ProjectCapability.DependenciesTree + " & " + ProjectCapabilities.PackageReferences)]
[AppliesTo(AppliesTo)]
internal sealed class PackageDependencyFactory : MSBuildDependencyFactoryBase
{
public const string AppliesTo = ProjectCapability.DependenciesTree + " & " + ProjectCapabilities.PackageReferences;

private static readonly DependencyFlagCache s_flagCache = new(
resolved: DependencyTreeFlags.PackageDependency + DependencyTreeFlags.SupportsFolderBrowse,
unresolved: DependencyTreeFlags.PackageDependency);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

namespace Microsoft.VisualStudio.ProjectSystem.Tree.Dependencies.Subscriptions.MSBuildDependencies;

// TODO also filter AppliesTo to ProjectCapabilities.ProjectReferences? same for other dependency types

[Export(typeof(IMSBuildDependencyFactory))]
[AppliesTo(ProjectCapability.DependenciesTree + " & " + ProjectCapabilities.ProjectReferences)]
[AppliesTo(AppliesTo)]
internal sealed class ProjectDependencyFactory : MSBuildDependencyFactoryBase
{
public const string AppliesTo = ProjectCapability.DependenciesTree + " & " + ProjectCapabilities.ProjectReferences;

private static readonly DependencyFlagCache s_flagCache = new(
resolved: DependencyTreeFlags.ProjectDependency + DependencyTreeFlags.SupportsBrowse,
unresolved: DependencyTreeFlags.ProjectDependency + DependencyTreeFlags.SupportsBrowse);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
namespace Microsoft.VisualStudio.ProjectSystem.Tree.Dependencies.Subscriptions.MSBuildDependencies;

[Export(typeof(IMSBuildDependencyFactory))]
[AppliesTo(ProjectCapability.DependenciesTree + " & " + ProjectCapabilities.SdkReferences)]
[AppliesTo(AppliesTo)]
internal class SdkDependencyFactory : MSBuildDependencyFactoryBase
{
public const string AppliesTo = ProjectCapability.DependenciesTree + " & " + ProjectCapabilities.SdkReferences;

private static readonly DependencyFlagCache s_flagCache = new(
resolved: DependencyTreeFlags.SdkDependency + DependencyTreeFlags.SupportsFolderBrowse,
unresolved: DependencyTreeFlags.SdkDependency);
Expand Down

0 comments on commit 267e898

Please sign in to comment.