/// <summary>
        /// Helper for metadata escaping tests
        /// </summary>
        private void SpecialCharactersInMetadataValueTests(Microsoft.Build.Evaluation.ProjectItem item)
        {
            Assert.AreEqual("%3B", item.GetMetadata("EscapedSemicolon").UnevaluatedValue);
            Assert.AreEqual(";", item.GetMetadata("EscapedSemicolon").EvaluatedValue);
            Assert.AreEqual(";", item.GetMetadataValue("EscapedSemicolon"));

            Assert.AreEqual("%24", item.GetMetadata("EscapedDollarSign").UnevaluatedValue);
            Assert.AreEqual("$", item.GetMetadata("EscapedDollarSign").EvaluatedValue);
            Assert.AreEqual("$", item.GetMetadataValue("EscapedDollarSign"));
        }
 public static ProjectMetadata ShouldContainMetadata(this ProjectItem item, string name, string because = "", params object[] becauseArgs)
 {
     return(item.GetMetadata(name)
            .Should()
            .NotBeNull(because, becauseArgs)
            .And
            .Subject
            .As <ProjectMetadata>());
 }
        private void ReplaceGuidMetadataIfExists(_BE.ProjectItem item, string metadataName)
        {
            string value = item.GetMetadata(metadataName).EvaluatedValue;

            if (!string.IsNullOrEmpty(value))
            {
                try
                {
                    Guid   g = new Guid(value);
                    string replaceWith;
                    if (guidDictionary.TryGetValue(g, out replaceWith))
                    {
                        //VS Guid replacements don't include braces
                        replaceWith = "{" + replaceWith + "}";
                        item.SetMetadataValue(metadataName, replaceWith);
                    }
                }
                catch (FormatException)
                {
                    Log.LogWarning("Item {0} has specified {1} metadata not in the format of a Guid.", item.EvaluatedInclude, metadataName);
                }
            }
        }
		void IProjectItemListProvider.AddProjectItem(ProjectItem item)
		{
			if (item == null)
				throw new ArgumentNullException("item");
			if (item.Project != this)
				throw new ArgumentException("item does not belong to this project", "item");
			if (item.IsAddedToProject)
				throw new ArgumentException("item is already added to project", "item");
			
			WorkbenchSingleton.AssertMainThread();
			using (var c = OpenCurrentConfiguration()) {
				items.Add(item);
				itemsReadOnly = null; // remove readonly variant of item list - will regenerate on next Items call
				/*foreach (var g in projectFile.ItemGroups) {
					if (!string.IsNullOrEmpty(g.Condition) || g.Count == 0)
						continue;
					var firstItemInGroup = g.Items.First();
					if (firstItemInGroup.Name == item.ItemType.ItemName) {
						MSBuildInternals.AddItemToGroup(g, item);
						return;
					}
					if (firstItemInGroup.ItemType == ItemType.Reference.ItemName)
						continue;
					if (ItemType.DefaultFileItems.Contains(new ItemType(firstItemInGroup.ItemType))) {
						if (ItemType.DefaultFileItems.Contains(item.ItemType)) {
							MSBuildInternals.AddItemToGroup(g, item);
							return;
						} else {
							continue;
						}
					}
					
					MSBuildInternals.AddItemToGroup(g, item);
					return;
				}
				var newGroup = projectFile.AddItemGroup();
				MSBuildInternals.AddItemToGroup(newGroup, item);*/
				
				
				string newInclude = item.TreatIncludeAsLiteral ? MSBuildInternals.Escape(item.Include) : item.Include;
				var newMetadata = new Dictionary<string, string>();
				foreach (string name in item.MetadataNames) {
					newMetadata[name] = item.GetMetadata(name);
				}
				var newItems = c.Project.AddItem(item.ItemType.ItemName, newInclude, newMetadata);
				if (newItems.Count != 1)
					throw new InvalidOperationException("expected one new item, but got " + newItems.Count);
				item.BuildItem = new MSBuildItemWrapper((MSBuildBasedProject)item.Project, newItems[0]);
				Debug.Assert(item.IsAddedToProject);
			}
		}
        /// <summary>
        /// Helper for SpecialCharactersInMetadataValue tests
        /// </summary>
        internal static void SpecialCharactersInMetadataValueTests(ProjectItem item)
        {
            Assert.Equal("%3B", item.GetMetadata("EscapedSemicolon").UnevaluatedValue);
            Assert.Equal("%3B", item.GetMetadata("EscapedSemicolon").EvaluatedValueEscaped);
            Assert.Equal(";", item.GetMetadata("EscapedSemicolon").EvaluatedValue);
            Assert.Equal("%3B", Project.GetMetadataValueEscaped(item, "EscapedSemicolon"));
            Assert.Equal(";", item.GetMetadataValue("EscapedSemicolon"));

            Assert.Equal("%24", item.GetMetadata("EscapedDollarSign").UnevaluatedValue);
            Assert.Equal("%24", item.GetMetadata("EscapedDollarSign").EvaluatedValueEscaped);
            Assert.Equal("$", item.GetMetadata("EscapedDollarSign").EvaluatedValue);
            Assert.Equal("%24", Project.GetMetadataValueEscaped(item, "EscapedDollarSign"));
            Assert.Equal("$", item.GetMetadataValue("EscapedDollarSign"));
        }
        public string GetMetadata(string name)
        {
            var m = item.GetMetadata(name);

            return(m != null ? m.UnevaluatedValue : null);
        }