Пример #1
0
        public override void BeforeAddOrUpdate(
            ITargetFramework targetFramework,
            IDependency dependency,
            IReadOnlyDictionary <string, IProjectDependenciesSubTreeProvider> subTreeProviderByProviderType,
            IImmutableSet <string>?projectItemSpecs,
            AddDependencyContext context)
        {
            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));
                    return;
                }
            }
            else if (dependency.Flags.Contains(DependencyTreeFlags.PackageDependency) && 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));
                }
            }

            context.Accept(dependency);
        }
        public override void BeforeAddOrUpdate(
            IDependency dependency,
            IReadOnlyDictionary <string, IProjectDependenciesSubTreeProvider> subTreeProviderByProviderType,
            IImmutableSet <string>?projectItemSpecs,
            AddDependencyContext context)
        {
            if (dependency.Flags.Contains(DependencyTreeFlags.SdkDependency))
            {
                // This is an SDK dependency.
                //
                // Try to find a resolved package dependency with the same name.

                if (context.TryGetDependency(new DependencyId(PackageRuleHandler.ProviderTypeString, dependency.Id), out IDependency package) && package.Resolved)
                {
                    // Set to resolved and clear any diagnostic.

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

                if (context.TryGetDependency(new DependencyId(SdkRuleHandler.ProviderTypeString, dependency.Id), 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 clear any diagnostic.

                    context.AddOrUpdate(sdk.ToResolved(
                                            schemaName: ResolvedSdkReference.SchemaName,
                                            diagnosticLevel: DiagnosticLevel.None));
                }
            }

            context.Accept(dependency);
        }