public int get_CanonicalName(out string pbstrCanonicalName) { // Get the output assembly path (including the name) pbstrCanonicalName = output.GetMetadataValue(ProjectFileConstants.FinalOutputPath); if (String.IsNullOrEmpty(pbstrCanonicalName)) { pbstrCanonicalName = output.EvaluatedInclude; } Debug.Assert(!String.IsNullOrEmpty(pbstrCanonicalName), "Output Assembly not defined"); // Make sure we have a full path if (!System.IO.Path.IsPathRooted(pbstrCanonicalName)) { pbstrCanonicalName = new Url(project.BaseURI, pbstrCanonicalName).AbsoluteUrl; } return(VSConstants.S_OK); }
private static void AssertItemHasMetadata(Dictionary<string, string> expected, ProjectItemInstance item) { Assert.Equal(expected.Keys.Count, item.DirectMetadataCount); foreach (var key in expected.Keys) { Assert.Equal(expected[key], item.GetMetadataValue(key)); } }
public static string GetMetadataValue(MSBuildExecution.ProjectItemInstance item, string name) { return(item.GetMetadataValue(name)); }
public void ModifyItemThatWasAddedInSameScope() { ProjectInstance project = ProjectHelpers.CreateEmptyProjectInstance(); ItemDictionary<ProjectItemInstance> table1 = new ItemDictionary<ProjectItemInstance>(); Lookup lookup = LookupHelpers.CreateLookup(table1); Lookup.Scope enteredScope = lookup.EnterScope("x"); // Add an item with m=m1 ProjectItemInstance item1 = new ProjectItemInstance(project, "i1", "a2", project.FullPath); item1.SetMetadata("m", "m1"); lookup.AddNewItem(item1); // Change the item to be m=m2 Lookup.MetadataModifications newMetadata = new Lookup.MetadataModifications(keepOnlySpecified: false); newMetadata.Add("m", "m2"); ICollection<ProjectItemInstance> group = new List<ProjectItemInstance>(); group.Add(item1); lookup.ModifyItems(item1.ItemType, group, newMetadata); // Now it has m=m2 group = lookup.GetItems("i1"); Assert.Equal(1, group.Count); Assert.Equal("m2", group.First().GetMetadataValue("m")); // But the original item hasn't changed yet Assert.Equal("m1", item1.GetMetadataValue("m")); enteredScope.LeaveScope(); // It still has m=m2 group = lookup.GetItems("i1"); Assert.Equal(1, group.Count); Assert.Equal("m2", group.First().GetMetadataValue("m")); // But now the original item has changed as well Assert.Equal("m2", item1.GetMetadataValue("m")); }
public void ModifyItemTwiceInSameScope2() { ProjectInstance project = ProjectHelpers.CreateEmptyProjectInstance(); ItemDictionary<ProjectItemInstance> table1 = new ItemDictionary<ProjectItemInstance>(); Lookup lookup = LookupHelpers.CreateLookup(table1); // Add an item with m=m1 and n=n1 and o=o1 ProjectItemInstance item1 = new ProjectItemInstance(project, "i1", "a2", project.FullPath); item1.SetMetadata("m", "m1"); item1.SetMetadata("n", "n1"); item1.SetMetadata("o", "o1"); lookup.PopulateWithItem(item1); Lookup.Scope enteredScope = lookup.EnterScope("x"); // It's still m=m1, n=n1, o=o1 ICollection<ProjectItemInstance> group = lookup.GetItems("i1"); Assert.Equal(1, group.Count); Assert.Equal("m1", group.First().GetMetadataValue("m")); Assert.Equal("n1", group.First().GetMetadataValue("n")); Assert.Equal("o1", group.First().GetMetadataValue("o")); // Make a modification to the item to be m=m2 and n=n2 Lookup.MetadataModifications newMetadata = new Lookup.MetadataModifications(keepOnlySpecified: false); newMetadata.Add("m", "m2"); newMetadata.Add("n", "n2"); group = new List<ProjectItemInstance>(); group.Add(item1); lookup.ModifyItems("i1", group, newMetadata); // It's now m=m2, n=n2, o=o1 ICollection<ProjectItemInstance> foundGroup = lookup.GetItems("i1"); Assert.Equal(1, foundGroup.Count); Assert.Equal("m2", foundGroup.First().GetMetadataValue("m")); Assert.Equal("n2", foundGroup.First().GetMetadataValue("n")); Assert.Equal("o1", foundGroup.First().GetMetadataValue("o")); // Make a modification to the item to be n=n3 newMetadata = new Lookup.MetadataModifications(keepOnlySpecified: false); newMetadata.Add("n", "n3"); lookup.ModifyItems("i1", group, newMetadata); // It's now m=m2, n=n3, o=o1 foundGroup = lookup.GetItems("i1"); Assert.Equal(1, foundGroup.Count); Assert.Equal("m2", foundGroup.First().GetMetadataValue("m")); Assert.Equal("n3", foundGroup.First().GetMetadataValue("n")); Assert.Equal("o1", foundGroup.First().GetMetadataValue("o")); // But the original item hasn't changed yet Assert.Equal("m1", item1.GetMetadataValue("m")); Assert.Equal("n1", item1.GetMetadataValue("n")); Assert.Equal("o1", item1.GetMetadataValue("o")); enteredScope.LeaveScope(); // It's still m=m2, n=n3, o=o1 foundGroup = lookup.GetItems("i1"); Assert.Equal(1, foundGroup.Count); Assert.Equal("m2", foundGroup.First().GetMetadataValue("m")); Assert.Equal("n3", foundGroup.First().GetMetadataValue("n")); Assert.Equal("o1", foundGroup.First().GetMetadataValue("o")); // And the original item has changed Assert.Equal("m2", item1.GetMetadataValue("m")); Assert.Equal("n3", item1.GetMetadataValue("n")); Assert.Equal("o1", item1.GetMetadataValue("o")); }
public void ModifyItemInProjectPreviouslyModifiedAndGottenThroughGetItem() { ProjectInstance project = ProjectHelpers.CreateEmptyProjectInstance(); // Create some project state with an item with m=m1 and n=n1 ItemDictionary<ProjectItemInstance> table1 = new ItemDictionary<ProjectItemInstance>(); ProjectItemInstance item1 = new ProjectItemInstance(project, "i1", "a2", project.FullPath); item1.SetMetadata("m", "m1"); table1.Add(item1); Lookup lookup = LookupHelpers.CreateLookup(table1); Lookup.Scope enteredScope = lookup.EnterScope("x"); // Make a modification to the item to be m=m2 Lookup.MetadataModifications newMetadata = new Lookup.MetadataModifications(keepOnlySpecified: false); newMetadata.Add("m", "m2"); List<ProjectItemInstance> group = new List<ProjectItemInstance>(); group.Add(item1); lookup.ModifyItems(item1.ItemType, group, newMetadata); // Get the item (under the covers, it cloned it in order to apply the modification) ICollection<ProjectItemInstance> group2 = lookup.GetItems(item1.ItemType); Assert.Equal(1, group2.Count); ProjectItemInstance item1b = group2.First(); // Modify to m=m3 Lookup.MetadataModifications newMetadata2 = new Lookup.MetadataModifications(keepOnlySpecified: false); newMetadata2.Add("m", "m3"); List<ProjectItemInstance> group3 = new List<ProjectItemInstance>(); group3.Add(item1b); lookup.ModifyItems(item1b.ItemType, group3, newMetadata2); // Modifications are visible ICollection<ProjectItemInstance> group4 = lookup.GetItems(item1b.ItemType); Assert.Equal(1, group4.Count); Assert.Equal("m3", group4.First().GetMetadataValue("m")); // Leave scope enteredScope.LeaveScope(); // Still visible ICollection<ProjectItemInstance> group5 = lookup.GetItems(item1b.ItemType); Assert.Equal(1, group5.Count); Assert.Equal("m3", group5.First().GetMetadataValue("m")); // And the one in the project is changed Assert.Equal("m3", item1.GetMetadataValue("m")); }