/// <summary> /// When some other project's snapshot changed we need to check if our snapshot has a top level /// dependency on changed project. If it does we need to refresh those top level dependencies to /// reflect changes. /// </summary> /// <param name="otherProjectSnapshot"></param> /// <param name="shouldBeResolved"> /// Specifies if top-level project dependencies resolved status. When other project just had it's dependencies /// changed, it is resolved=true (we check target's support when we add project dependencies). However when /// other project is unloaded, we should mark top-level dependencies as unresolved. /// </param> private void OnOtherProjectDependenciesChanged(IDependenciesSnapshot otherProjectSnapshot, bool shouldBeResolved) { IDependenciesSnapshot projectSnapshot = SnapshotProvider.CurrentSnapshot; if (otherProjectSnapshot == null || projectSnapshot == null || projectSnapshot.Equals(otherProjectSnapshot)) { // if any of the snapshots is not provided or this is the same project - skip return; } string otherProjectPath = otherProjectSnapshot.ProjectPath; var dependencyThatNeedChange = new List <IDependency>(); foreach (KeyValuePair <ITargetFramework, ITargetedDependenciesSnapshot> target in projectSnapshot.Targets) { foreach (IDependency dependency in target.Value.TopLevelDependencies) { // We're only interested in project dependencies if (!StringComparers.DependencyProviderTypes.Equals(dependency.ProviderType, ProviderTypeString)) { continue; } if (!StringComparers.Paths.Equals(otherProjectPath, dependency.FullPath)) { continue; } dependencyThatNeedChange.Add(dependency); break; } } if (dependencyThatNeedChange.Count == 0) { // we don't have dependency on updated project return; } foreach (IDependency dependency in dependencyThatNeedChange) { IDependencyModel model = CreateDependencyModel( ProviderType, dependency.Path, dependency.OriginalItemSpec, shouldBeResolved, dependency.Implicit, dependency.Properties); var changes = new DependenciesChanges(); // avoid unnecessary removing since, add would upgrade dependency in snapshot anyway, // but remove would require removing item from the tree instead of in-place upgrade. if (!shouldBeResolved) { changes.IncludeRemovedChange(model); } changes.IncludeAddedChange(model); FireDependenciesChanged( new DependenciesChangedEventArgs( this, dependency.TargetFramework.FullName, changes, catalogs: null, dataSourceVersions: null)); } }