/// <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 projec dependencies). However when /// other project is unloaded, we should mark top-level dependencies as unresolved. /// </param> private void OnOtherProjectDependenciesChanged(IDependenciesSnapshot otherProjectSnapshot, bool shouldBeResolved) { var 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; } var otherProjectPath = otherProjectSnapshot.ProjectPath; var dependencyThatNeedChange = new List <IDependency>(); foreach (var target in projectSnapshot.Targets) { foreach (var 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 (var dependency in dependencyThatNeedChange) { var 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)); } }
/// <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="thisProjectSnapshot"></param> /// <param name="otherProjectSnapshot"></param> /// <param name="shouldBeResolved"> /// Specifies if top-level project dependencies resolved status. When other project just had its 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> /// <param name="token"></param> private void OnOtherProjectDependenciesChanged( IDependenciesSnapshot thisProjectSnapshot, IDependenciesSnapshot otherProjectSnapshot, bool shouldBeResolved, CancellationToken token) { if (token.IsCancellationRequested || StringComparers.Paths.Equals(thisProjectSnapshot.ProjectPath, otherProjectSnapshot.ProjectPath)) { // if any of the snapshots is not provided or this is the same project - skip return; } string otherProjectPath = otherProjectSnapshot.ProjectPath; List <IDependency> dependencyThatNeedChange = null; foreach (ITargetedDependenciesSnapshot targetedDependencies in thisProjectSnapshot.Targets.Values) { foreach (IDependency dependency in targetedDependencies.TopLevelDependencies) { // We're only interested in project dependencies if (!StringComparers.DependencyProviderTypes.Equals(dependency.ProviderType, ProviderTypeString)) { continue; } if (!StringComparers.Paths.Equals(otherProjectPath, dependency.FullPath)) { continue; } if (dependencyThatNeedChange == null) { dependencyThatNeedChange = new List <IDependency>(capacity: thisProjectSnapshot.Targets.Count); } dependencyThatNeedChange.Add(dependency); break; } } if (dependencyThatNeedChange == null) { // we don't have dependency on updated project return; } foreach (IDependency dependency in dependencyThatNeedChange) { if (token.IsCancellationRequested) { return; } IDependencyModel model = CreateDependencyModel( 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(ProviderTypeString, model.Id); } changes.IncludeAddedChange(model); FireDependenciesChanged( new DependenciesChangedEventArgs( this, dependency.TargetFramework.FullName, changes, token)); } }