public override void Execute(CancellationToken cancellationToken) { var resPath = this.GetResourceFilePath(); if (resPath == null) { return; } var vs = new VisualStudioTextManipulation(ProjectHelpers.Dte); vs.StartSingleUndoOperation(StringRes.Info_UndoContextMoveStringToResourceFile); try { // If the resource file is open with unsaved changes VS will prompt about data being lost. this.AddResource(resPath, $"{this.Tag.UidValue}.{this.Tag.AttributeName}", this.Tag.Value); if (this.Tag.AttributeType == AttributeType.Inline) { var currentAttribute = $"{this.Tag.AttributeName}=\"{this.Tag.Value}\""; if (this.Tag.UidExists) { vs.RemoveInActiveDocOnLine(currentAttribute, this.Tag.GetDesignerLineNumber()); } else { var uidTag = $"x:Uid=\"{this.Tag.UidValue}\""; vs.ReplaceInActiveDocOnLine(currentAttribute, uidTag, this.Tag.GetDesignerLineNumber()); } } else if (this.Tag.AttributeType == AttributeType.Element) { var currentAttribute = $"<{this.Tag.ElementName}.{this.Tag.AttributeName}>{this.Tag.Value}</{this.Tag.ElementName}.{this.Tag.AttributeName}>"; vs.RemoveInActiveDocOnLine(currentAttribute, this.Tag.GetDesignerLineNumber()); if (!this.Tag.UidExists) { var uidTag = $"<{this.Tag.ElementName} x:Uid=\"{this.Tag.UidValue}\""; vs.ReplaceInActiveDocOnLineOrAbove($"<{this.Tag.ElementName}", uidTag, this.Tag.GetDesignerLineNumber()); } } else if (this.Tag.AttributeType == AttributeType.DefaultValue) { var current = $">{this.Tag.Value}</{this.Tag.ElementName}>"; var replaceWith = this.Tag.UidExists ? " />" : $" x:Uid=\"{this.Tag.UidValue}\" />"; vs.ReplaceInActiveDocOnLine(current, replaceWith, this.Tag.GetDesignerLineNumber()); } RapidXamlDocumentCache.TryUpdate(this.File); } finally { vs.EndSingleUndoOperation(); } }