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); }
public override void BeforeAddOrUpdate( ITargetFramework targetFramework, IDependency dependency, IReadOnlyDictionary <string, IProjectDependenciesSubTreeProvider> subTreeProviderByProviderType, IImmutableSet <string>?projectItemSpecs, AddDependencyContext context) { IDependency?matchingDependency = null; bool shouldApplyAlias = false; foreach ((string _, IDependency other) in context) { if (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;
public override void BeforeAddOrUpdate( IDependency dependency, AddDependencyContext context) { IDependency?matchingDependency = null; bool shouldApplyAlias = false; foreach ((DependencyId _, IDependency other) in context) { if (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 (Suffix)". string?suffix = GetSuffix(other); if (suffix != null) { int expectedItemSpecIndex = dependency.Caption.Length + 2; // " (".Length int expectedLength = expectedItemSpecIndex + suffix.Length + 1; // ")".Length if (other.Caption.Length == expectedLength && string.Compare(other.Caption, expectedItemSpecIndex, suffix, 0, suffix.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;