/// <summary> /// Removes references that have /// the Temp attribute and which /// were added from the Dependencies /// and FrameworkAssemblies sections /// of the lock file. /// </summary> public virtual IEnumerable <string> SwitchDependency(IProjectReference reference, ReferenceType type) { HashSet <string> output = new HashSet <string> (); foreach (ProjectItem item in GetTempItem(reference, type)) { if (type == ReferenceType.ProjectReference) { output.Add(item.EvaluatedInclude); } // Implicit. if (!item.HasMetadata("Version")) { reference.MsbProject.RemoveItem(item); } // Explicit. else { item.UnevaluatedInclude = item.GetMetadataValue("Temp"); item.RemoveMetadata("Temp"); item.RemoveMetadata("Name"); item.ItemType = Type.ToString(); } MessageProvider.AddMessage(reference.UniqueName, $"Dependency: { Path.GetFileNameWithoutExtension(item.EvaluatedInclude) } has been switched back. Type: { Type }", MessageCategory.ME); } return(output); }
/// <summary> /// Callback for <see cref="MenuCommand"/>. /// </summary> public override void Callback(object sender, EventArgs eventArgs) { try { CommandProvider.Route(Name); } catch (Exception exception) { MessageProvider.AddMessage(exception); } }
/// <summary> /// Includes implicit, explicit project references /// listed in the Dependencies section of the lock /// file. /// </summary> /// /// <exception cref="SwitcherException"/> /// /// <remarks> /// Implicit dependencies mean transitive. /// </remarks> public virtual void SwitchPkgDependency(IProjectReference reference, LockFileTargetLibrary library, string absolutePath) { /* * References can be represented by several values in * an ItemGroup, for example, when included using the * Condition attribute. */ ICollection <ProjectItem> items = reference.MsbProject.GetItemsByEvaluatedInclude(library.Name); // Implicit. if (!items.Any()) { base.AddReference(reference, Type, absolutePath, new Dictionary <string, string>(2) { { "Name", library.Name } }); } // Explicit. else { /* * Re-creating an item can lead to the loss * of user metadata; in order to avoid this, * the item is redefined. */ foreach (ProjectItem item in items) { item.ItemType = Type.ToString(); item.SetMetadataValue("Temp", item.EvaluatedInclude); item.SetMetadataValue("Name", item.EvaluatedInclude); item.UnevaluatedInclude = absolutePath; } MessageProvider.AddMessage(reference.MsbProject.FullPath, $"Dependency: {library.Name } has been switched. Type: { Type }", MessageCategory.ME); } }