private Reference AddFromProjectReference(IContext context, string path, object project) { Project dteProject = null; ShellProject shellProject = project as ShellProject; if (null != shellProject) { dteProject = shellProject.AsProject(); } if (null == dteProject) { dteProject = project as Project; } if (null == dteProject) { dteProject = ResolveProject(context, project.ToString()); } if (null == dteProject && !string.IsNullOrEmpty(path)) { dteProject = ResolveProject(context, path); } if (null == dteProject) { return(null); } return(_references.AddProject(dteProject)); }
public IPathNode CopyItem(IContext context, string path, string copyPath, IPathNode destinationContainer, bool recurse) { ProjectItems destinationItems = null; ShellProject destinationProject = destinationContainer.Item as ShellProject; ShellProjectItem destinationItem = destinationContainer.Item as ShellProjectItem; if (null == destinationProject) { var containerKinds = new[] { Constants.vsProjectItemKindPhysicalFolder, Constants.vsProjectItemsKindSolutionItems, Constants.vsProjectItemKindSubProject, Constants.vsProjectItemKindVirtualFolder, }; if (null == destinationItem || !containerKinds.Contains(destinationItem.Kind)) { throw new InvalidOperationException( "Project items can only be moved or copied into a project node, a project folder, or solution folder."); } destinationItems = destinationItem.AsProjectItem().ProjectItems; destinationProject = destinationItem.ContainingProject; } else { destinationItems = destinationProject.AsProject().ProjectItems; } ShellProject sourceProject = new ShellProject(_item.ContainingProject); bool isWithinProject = sourceProject.UniqueName == destinationProject.UniqueName; if (String.IsNullOrEmpty(copyPath)) { if (isWithinProject) { copyPath = "Copy of " + path; } else { copyPath = path; } } ProjectItem newItem = null; CopyItemContext copyContext = null; var events = ((Events2)_item.DTE.Events); copyContext = new CopyItemContext(_item, copyPath, destinationItems, isWithinProject, recurse); events.ProjectItemsEvents.ItemAdded += copyContext.OnItemAdded; Exception error = null; AddItemCopy(copyContext, out error); events.ProjectItemsEvents.ItemAdded -= copyContext.OnItemAdded; if (null != error) { context.WriteError(new ErrorRecord( new CopyOrMoveItemInternalException(path, copyContext.CopyPath, error), "StudioShell.CopyItem.Internal", ErrorCategory.WriteError, path)); return(null); } return(new PathNode(ShellObjectFactory.CreateFromProjectItem(newItem), copyPath, false)); }