/// <summary> /// Renames the item. /// Equivalent to setting the <see cref="UnevaluatedInclude"/> value. /// Generally, no expansion occurs. This is because it would potentially result in several items, /// which is not meaningful semantics when renaming a single item. /// However if the item does not need to be split (which would invalidate its ProjectItemElement), /// and the new value expands to exactly one item, then its evaluated include is updated /// with the expanded value, rather than the unexpanded value. /// </summary> /// <remarks> /// Even if the new value expands to zero items, we do not expand it. /// The common case we are interested in for expansion here is setting something /// like "$(sourcesroot)\foo.cs" and expanding that to a single item. /// If say "@(foo)" is set as the new name, and it expands to blank, that might /// be surprising to the host and maybe even unhandled, if on full reevaluation /// it wouldn’t expand to blank. That’s why we're being cautious and supporting /// the most common scenario only. /// Many hosts will do a ReevaluateIfNecessary before reading anyway. /// </remarks> public void Rename(string name) { if (Link != null) { Link.Rename(name); return; } Project.VerifyThrowInvalidOperationNotImported(_xml.ContainingProject); ErrorUtilities.VerifyThrowInvalidOperation(_xml.Parent != null && _xml.Parent.Parent != null, "OM_ObjectIsNoLongerActive"); if (String.Equals(UnevaluatedInclude, name, StringComparison.Ordinal)) { return; } _fullPath = null; // Clear cached value if (_xml.Count == 0 /* no metadata */ && _project.IsSuitableExistingItemXml(_xml, name, null /* no metadata */) && !FileMatcher.HasWildcardsSemicolonItemOrPropertyReferences(name)) { _evaluatedIncludeEscaped = name; // Fast item lookup tables are invalid now. // Make sure that when the caller invokes ReevaluateIfNecessary() that they'll be refreshed. Project.MarkDirty(); return; } bool splitOccurred = _project.SplitItemElementIfNecessary(_xml); _xml.Include = name; if (splitOccurred) { _evaluatedIncludeEscaped = name; } else { _evaluatedIncludeEscaped = _project.ExpandItemIncludeBestEffortLeaveEscaped(_xml); } }