public virtual void BeforeRemove(
     ITargetFramework targetFramework,
     IDependency dependency,
     RemoveDependencyContext context)
 {
     context.Accept();
 }
Exemple #2
0
        public override void BeforeRemove(
            ITargetFramework targetFramework,
            IDependency dependency,
            RemoveDependencyContext context)
        {
            if (dependency.TopLevel &&
                dependency.Resolved &&
                dependency.Flags.Contains(DependencyTreeFlags.NuGetPackageDependency))
            {
                // 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,
                                            dependencyIDs: ImmutableArray <string> .Empty));
                }
            }

            context.Accept();
        }