public virtual void BeforeAddOrUpdate(
     ITargetFramework targetFramework,
     IDependency dependency,
     IReadOnlyDictionary <string, IProjectDependenciesSubTreeProvider> subTreeProviderByProviderType,
     IImmutableSet <string>?projectItemSpecs,
     AddDependencyContext context)
 {
     context.Accept(dependency);
 }
示例#2
0
        public override void BeforeAddOrUpdate(
            ITargetFramework targetFramework,
            IDependency dependency,
            IReadOnlyDictionary <string, IProjectDependenciesSubTreeProvider> subTreeProviderByProviderType,
            IImmutableSet <string>?projectItemSpecs,
            AddDependencyContext context)
        {
            if (!dependency.TopLevel)
            {
                context.Accept(dependency);
                return;
            }

            if (dependency.Flags.Contains(DependencyTreeFlags.SdkDependency))
            {
                // This is an SDK dependency.
                //
                // Try to find a resolved package dependency with the same name.

                string packageId = Dependency.GetID(targetFramework, PackageRuleHandler.ProviderTypeString, modelId: dependency.Name);

                if (context.TryGetDependency(packageId, out IDependency package) && package.Resolved)
                {
                    // Set to resolved, and copy dependencies.

                    context.Accept(dependency.ToResolved(
                                       schemaName: ResolvedSdkReference.SchemaName,
                                       dependencyIDs: package.DependencyIDs));
                    return;
                }
            }
            else if (dependency.Flags.Contains(DependencyTreeFlags.NuGetPackageDependency) && dependency.Resolved)
            {
                // This is a resolved package dependency.
                //
                // Try to find an SDK dependency with the same name.

                string sdkId = Dependency.GetID(targetFramework, SdkRuleHandler.ProviderTypeString, modelId: dependency.Name);

                if (context.TryGetDependency(sdkId, out IDependency sdk))
                {
                    // We have an SDK dependency for this package. Such dependencies, when implicit, are created
                    // as unresolved by SdkRuleHandler, and are only marked resolved here once we have resolved the
                    // corresponding package.
                    //
                    // Set to resolved, and copy dependencies.

                    context.AddOrUpdate(sdk.ToResolved(
                                            schemaName: ResolvedSdkReference.SchemaName,
                                            dependencyIDs: dependency.DependencyIDs));
                }
            }

            context.Accept(dependency);
        }
        public override void BeforeAddOrUpdate(
            ITargetFramework targetFramework,
            IDependency dependency,
            IReadOnlyDictionary <string, IProjectDependenciesSubTreeProvider> subTreeProviderByProviderType,
            IImmutableSet <string>?projectItemSpecs,
            AddDependencyContext context)
        {
            // TODO should this verify that the existing one is actually resolved?
            if (!dependency.Resolved && context.Contains(dependency.Id))
            {
                context.Reject();
                return;
            }

            context.Accept(dependency);
        }
示例#4
0
        public override void BeforeAddOrUpdate(
            ITargetFramework targetFramework,
            IDependency dependency,
            IReadOnlyDictionary <string, IProjectDependenciesSubTreeProvider> subTreeProviderByProviderType,
            IImmutableSet <string>?projectItemSpecs,
            AddDependencyContext context)
        {
            if (dependency.TopLevel &&
                dependency.Resolved &&
                dependency.Flags.Contains(DependencyTreeFlags.ProjectDependency) &&
                !dependency.Flags.Contains(DependencyTreeFlags.SharedProjectFlags))
            {
                TargetedDependenciesSnapshot?snapshot = _aggregateSnapshotProvider.GetSnapshot(dependency);

                if (snapshot != null && snapshot.HasReachableVisibleUnresolvedDependency)
                {
                    context.Accept(dependency.ToUnresolved(ProjectReference.SchemaName));
                    return;
                }
            }

            context.Accept(dependency);
        }
        public override void BeforeAddOrUpdate(
            ITargetFramework targetFramework,
            IDependency dependency,
            IReadOnlyDictionary <string, IProjectDependenciesSubTreeProvider> subTreeProviderByProviderType,
            IImmutableSet <string>?projectItemSpecs,
            AddDependencyContext context)
        {
            if (projectItemSpecs != null &&                                           // must have data
                dependency.TopLevel &&                                                // top-level
                !dependency.Implicit &&                                               // explicit
                dependency.Resolved &&                                                // resolved
                dependency.Flags.Contains(DependencyTreeFlags.GenericDependency) &&   // generic dependency
                !dependency.Flags.Contains(DependencyTreeFlags.SharedProjectFlags) && // except for shared projects
                !projectItemSpecs.Contains(dependency.OriginalItemSpec) &&            // is not a known item spec
                subTreeProviderByProviderType.TryGetValue(dependency.ProviderType, out IProjectDependenciesSubTreeProvider provider) &&
                provider is IProjectDependenciesSubTreeProviderInternal internalProvider)
            {
                // Obtain custom implicit icon
                ImageMoniker implicitIcon = internalProvider.ImplicitIcon;

                // Obtain a pooled icon set with this implicit icon
                DependencyIconSet implicitIconSet = DependencyIconSetCache.Instance.GetOrAddIconSet(
                    implicitIcon,
                    implicitIcon,
                    dependency.IconSet.UnresolvedIcon,
                    dependency.IconSet.UnresolvedExpandedIcon);

                context.Accept(
                    dependency.SetProperties(
                        iconSet: implicitIconSet,
                        isImplicit: true));
                return;
            }

            context.Accept(dependency);
        }
        public override void BeforeAddOrUpdate(
            ITargetFramework targetFramework,
            IDependency dependency,
            IReadOnlyDictionary <string, IProjectDependenciesSubTreeProvider> subTreeProviderByProviderType,
            IImmutableSet <string>?projectItemSpecs,
            AddDependencyContext context)
        {
            // Only apply to top-level dependencies
            if (!dependency.TopLevel)
            {
                context.Accept(dependency);
                return;
            }

            IDependency?matchingDependency = null;
            bool        shouldApplyAlias   = false;

            foreach ((string _, IDependency other) in context)
            {
                if (!other.TopLevel ||
                    StringComparers.DependencyTreeIds.Equals(other.Id, dependency.Id) ||
                    !StringComparers.DependencyProviderTypes.Equals(other.ProviderType, dependency.ProviderType))
                {
                    continue;
                }

                if (other.Caption.StartsWith(dependency.Caption, StringComparisons.ProjectTreeCaptionIgnoreCase))
                {
                    if (other.Caption.Length == dependency.Caption.Length)
                    {
                        // Exact match.
                        matchingDependency = other;
                        shouldApplyAlias   = true;
                        break;
                    }

                    // Prefix matches.
                    // Check whether we have a match of form "Caption (ItemSpec)".

                    string itemSpec = other.OriginalItemSpec;
                    int    expectedItemSpecIndex = dependency.Caption.Length + 2;               // " (".Length
                    int    expectedLength        = expectedItemSpecIndex + itemSpec.Length + 1; // ")".Length

                    if (other.Caption.Length == expectedLength &&
                        string.Compare(other.Caption, expectedItemSpecIndex, itemSpec, 0, itemSpec.Length, StringComparisons.ProjectTreeCaptionIgnoreCase) == 0)
                    {
                        shouldApplyAlias = true;
                    }
                }
            }

            if (shouldApplyAlias)
            {
                if (matchingDependency != null)
                {
                    // Change the matching dependency's alias too
                    context.AddOrUpdate(matchingDependency.SetProperties(caption: GetAlias(matchingDependency)));
                }

                // Use the alias for the caption
                context.Accept(dependency.SetProperties(caption: GetAlias(dependency)));
            }
            else
            {
                // Accept without changes
                context.Accept(dependency);
            }

            return;