public override void BeforeRemove(
            IDependency dependency,
            RemoveDependencyContext context)
        {
            if (dependency.Resolved &&
                dependency.Flags.Contains(DependencyTreeFlags.PackageDependency))
            {
                // This is a 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 are removing the package dependency related to this SDK dependency
                    // and must undo the changes made above in BeforeAddOrUpdate.
                    //
                    // Set to unresolved and reinstate warning diagnostic.

                    context.AddOrUpdate(sdk.ToUnresolved(
                                            schemaName: SdkReference.SchemaName,
                                            diagnosticLevel: DiagnosticLevel.Warning));
                }
            }

            context.Accept();
        }
Esempio n. 2
0
        public override void BeforeRemove(
            ITargetFramework targetFramework,
            IDependency dependency,
            RemoveDependencyContext context)
        {
            if (dependency.Resolved &&
                dependency.Flags.Contains(DependencyTreeFlags.PackageDependency))
            {
                // This is a 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 are removing the package dependency related to this SDK dependency
                    // and must undo the changes made above in BeforeAdd.
                    //
                    // Set to unresolved, and clear dependencies.

                    context.AddOrUpdate(sdk.ToUnresolved(
                                            schemaName: SdkReference.SchemaName));
                }
            }

            context.Accept();
        }