private void AddItemTemplate(Project rootproject)
        {
            DTE    dte         = (DTE)GetService(typeof(DTE));
            string projectPath = DteHelper.BuildPath(rootproject);
            string folderPath  = projectPath;

            if (!string.IsNullOrEmpty(this.Path))
            {
                folderPath = System.IO.Path.Combine(folderPath, this.Path);
            }
            ProjectItem prItem = DteHelper.FindItemByPath(dte.Solution, folderPath);

            if (prItem != null)
            {
                this.NewItem = prItem.ProjectItems.AddFromTemplate(this.Template, this.ItemName);
            }
            else
            {
                Project project = DteHelper.FindProjectByPath(dte.Solution, folderPath);
                if (project != null)
                {
                    project.ProjectItems.AddFromTemplate(this.Template, this.ItemName);
                }
                else
                {
                    throw new InvalidOperationException(
                              String.Format(CultureInfo.CurrentUICulture, Resources.InsertionPointException, folderPath));
                }
            }
        }
        /// <summary>
        /// Ensures Physical Folder existence
        /// </summary>
        public override void Execute()
        {
            EnvDTE.DTE vs = (EnvDTE.DTE)GetService(typeof(EnvDTE.DTE));
            path = "";

            // TODO: this code should be in DteHelper
            // In some case vs.Solution.FullName == ""
            if (vs.Solution.FullName != "")
            {
                path = DteHelper.GetPathFull(vs, DteHelper.BuildPath(solutionFolder));
            }
            else
            {
                Property property = vs.Solution.Properties.Item("Path");
                path = System.IO.Path.GetDirectoryName(property.Value.ToString());

                path = System.IO.Path.Combine(path, DteHelper.BuildPath(solutionFolder));
            }

            if (!string.IsNullOrEmpty(path))
            {
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
            }
            else
            {
                // throw an exception.
            }
        }
예제 #3
0
        private void AddItemTemplate(Project rootproject)
        {
            DTE    dte         = (DTE)GetService(typeof(DTE));
            string projectPath = DteHelper.BuildPath(rootproject);
            string folderPath  = projectPath;

            if (!string.IsNullOrEmpty(this.Path))
            {
                folderPath += "\\" + this.Path;
            }
            ProjectItem prItem = DteHelper.FindItemByPath(dte.Solution, folderPath);

            if (prItem != null)
            {
                this.NewItem =
                    prItem.ProjectItems.AddFromTemplate(this.Template, this.ItemName);
            }
            else
            {
                Project project = DteHelper.FindProjectByPath(dte.Solution, folderPath);
                if (project != null)
                {
                    this.NewItem =
                        project.ProjectItems.AddFromTemplate(this.Template, this.ItemName);
                }
                else
                {
                    throw new InvalidOperationException(
                              String.Format("Cannot find insertion point {0}", folderPath));
                }
            }
        }
        // Methods
        private void AddItemTemplate(Project rootproject)
        {
            DTE    service = (DTE)this.GetService(typeof(DTE));
            string str2    = DteHelper.BuildPath(rootproject);

            if (!string.IsNullOrEmpty(this.Path))
            {
                str2 = System.IO.Path.Combine(str2, this.Path);
            }
            ProjectItem item = DteHelper.FindItemByPath(service.Solution, str2);

            if (item != null)
            {
                this.NewItem = item.ProjectItems.AddFromTemplate(this.Template, this.ItemName);
            }
            else
            {
                Project project = DteHelper.FindProjectByPath(service.Solution, str2);
                if (project == null)
                {
                    throw new InvalidOperationException(string.Format(CultureInfo.CurrentUICulture, "InsertionPointException", new object[] { str2 }));
                }
                project.ProjectItems.AddFromTemplate(this.Template, this.ItemName);
            }
        }
예제 #5
0
        /// <summary>
        /// Adds the new output from the specified parameters
        /// </summary>
        public override void Execute()
        {
            IVsdDeployable deployable = (IVsdDeployable)SetupProject.Object;
            IVsdProject    project    = (IVsdProject)deployable.GetParent();

            if (Folder == null)
            {
                project.AddOutputGroup(ProjectOutputKind, InputProject.UniqueName);
            }
            else // Folder is not null, so let's add it manually
            {
                IVsdCollectionSubset    plugins        = deployable.GetPlugIns();
                IVsdProjectOutputPlugIn projectsPlugin = plugins.Item("ProjectOutput") as IVsdProjectOutputPlugIn;
                projectOutput =
                    (IVsdProjectOutputGroup)DteHelper.CoCreateInstance(
                        this.Site,
                        typeof(VsdProjectOutputGroupClass),
                        typeof(IVsdProjectOutputGroup));
                //projectOutput.OutputConfig = null;
                projectOutput.OutputGroup   = ProjectOutputKind;
                projectOutput.OutputProject = InputProject.UniqueName;
                projectOutput.ShowKeyOutput = true;
                projectOutput.Folder        = vsdFolder;
                projectsPlugin.Items.Add(projectOutput);
            }
            // Collapse to project definition.
            UIHierarchyItem uiitem = DteHelper.SelectItem(SetupProject.DTE,
                                                          DteHelper.BuildPath(SetupProject));

            if (uiitem != null)
            {
                uiitem.UIHierarchyItems.Expanded = false;
            }
        }
예제 #6
0
        private string BuildItemKey(ProjectItem item)
        {
            string itemVirtualPath = DteHelper.BuildPath(item);

            itemVirtualPath = itemVirtualPath.Replace(".", "__").Replace("\\", "___");

            return(itemVirtualPath);
        }
예제 #7
0
        private void DeleteItem(ProjectItem projectItem, DTE vs)
        {
            string itemPath = DteHelper.BuildPath(projectItem);

            itemPath = DteHelper.GetPathFull(vs, itemPath);

            projectItem.Remove();
            projectItem.Delete();
        }
예제 #8
0
        /// <summary>
        /// Converts an element into its path location relative to the solution.
        /// </summary>
        public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
        {
            // Ensure only projects are converted and only to string.
            if (destinationType != typeof(string) ||
                !(value is Reference))
            {
                throw new ArgumentException(Properties.Resources.ReferenceConverter_InvalidConversion);
            }
            Reference r = (Reference)value;

            return(DteHelper.BuildPath(r.ContainingProject) + "\\" +
                   Properties.Resources.ReferenceConverter_ReferencesNode + "\\" + r.Name);
        }
예제 #9
0
        /// <summary>
        /// Delete ProjectItems content filtering by the input kind guid
        /// </summary>
        public override void Execute()
        {
            foreach (ProjectItem projectItem in projectItems)
            {
                if ((string.IsNullOrEmpty(kind) || (projectItem.Kind == kind)))
                {
                    DTE    vs       = (DTE)GetService(typeof(DTE));
                    string itemPath = DteHelper.BuildPath(projectItem);
                    itemPath = DteHelper.GetPathFull(vs, itemPath);

                    projectItem.Delete();

                    File.Delete(itemPath);
                }
            }
        }
예제 #10
0
        /// <summary>
        /// Converts an element into its path location relative to the solution.
        /// </summary>
        public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
        {
            // We only support special conversion to string and from our known types.
            if (destinationType != typeof(string) ||
                !(value is Solution ||
                  value is EnvDTE80.SolutionFolder ||
                  value is Project ||
                  value is ProjectItem))
            {
                return(base.ConvertTo(context, culture, value, destinationType));
            }

            // The helper requests the service and ensures that it exists.
            if (value is Solution)
            {
                return("\\");
            }
            else
            {
                return("\\" + DteHelper.BuildPath(value));
            }
        }
예제 #11
0
        public override bool OnBeforeActions(object currentValue, out object newValue)
        {
            IDictionaryService dictionaryService = (IDictionaryService)GetService <IDictionaryService>();
            ProjectItem        folder            = dictionaryService.GetValue(folderArgumentName) as ProjectItem;

            if (folder != null)
            {
                Project project = folder.ContainingProject;
                string  path    = DteHelper.BuildPath(folder);
                path = path.Replace(DteHelper.BuildPath(folder.ContainingProject), string.Empty);
                path = path.Replace(Path.DirectorySeparatorChar, NamespaceHelper.NamespaceSeparatorChar);
                if (path.StartsWith(NamespaceHelper.NamespaceSeparator))
                {
                    path = path.Substring(NamespaceHelper.NamespaceSeparator.Length);
                }
                newValue = path;
            }
            else
            {
                newValue = currentValue;
            }
            return(true);
        }
        /// <summary>
        /// The method that creates a new item from the input string.
        /// </summary>
        public override void Execute()
        {
            if (ownerItem == null && ownerProject == null)
            {
                throw new ArgumentNullException(Properties.Resources.OwnerProjectOrItemRequired);
            }

            if (ownerItem != null)
            {
                ownerProject = ownerItem.ContainingProject;
                // If we got a parent item, build the virtual path to it
                // for the real full path we will work againt.
                string itemPath = String.Empty;
                DteHelper.BuildPathFromCollection(ownerProject.ProjectItems, ownerItem, ref itemPath);
                path = System.IO.Path.Combine(itemPath, path);
            }

            DTE         vs = GetService <DTE>();
            ProjectItem containingFolder;
            string      targetPath;

            using (EnsureProjectFolderAction ensureFolder = new EnsureProjectFolderAction())
            {
                this.Site.Container.Add(ensureFolder);
                ensureFolder.Path         = path;
                ensureFolder.OwnerProject = ownerProject;
                ensureFolder.Execute();
                containingFolder = ensureFolder.TargetFolder;
            }

            if (containingFolder.Object is Project)
            {
                containingFolder = new ProjectProjectItemAdapter((Project)containingFolder.Object);
            }

            using (EvaluateExpressionAction evaluateExpression = new EvaluateExpressionAction())
            {
                this.Site.Container.Add(evaluateExpression);
                evaluateExpression.Expression = path;
                evaluateExpression.Execute();
                targetPath = evaluateExpression.ReturnValue.ToString();
            }

            string targetFileName = System.IO.Path.GetFileName(targetPath);

            // This may be different than the containingFolder variable,
            // as the EnsureProjectFolder only ensures folders, not
            // hierarchy of dependent items. So we need to look for
            // the actual parent which may be a project item, not a folder.
            ProjectItem parent = DteHelper.FindItemByPath(
                vs.Solution,
                System.IO.Path.Combine(
                    DteHelper.BuildPath(ownerProject),

                    /* This call just strips the last segment in the path. "Directory"
                     * can still be a file name, as in the case of dependent items */
                    System.IO.Path.GetDirectoryName(targetPath)
                    )
                );

            if (parent == null)
            {
                parent = containingFolder;
            }

            Debug.Assert(parent != null, "Didn't find parent with path: " + targetPath);

            addedItem = DteHelper.FindItemByName(parent.ProjectItems, targetFileName, false);
            if (addedItem != null)
            {
                if (overwrite)
                {
                    OverwriteFile(vs, addedItem.get_FileNames(1), content);
                    addedItem.Delete();
                }
            }

            addedItem = DteHelper.FindItemByName(parent.ProjectItems, targetFileName, false);
            if (addedItem == null)
            {
                // At the FS level, dependent files are always inside the folder we determined
                // above using the EnsureProjectFolderAction.
                string folderPath = System.IO.Path.Combine(
                    System.IO.Path.GetDirectoryName(ownerProject.FileName),
                    DteHelper.BuildPath(containingFolder));
                string fullPath = System.IO.Path.Combine(folderPath, targetFileName);
                if (File.Exists(fullPath))
                {
                    OverwriteFile(vs, fullPath, content);
                    addedItem = parent.ProjectItems.AddFromFile(fullPath);
                }
                else
                {
                    string tempfile = System.IO.Path.GetTempFileName();
                    try
                    {
                        File.WriteAllText(tempfile, content);
                        addedItem = parent.ProjectItems.AddFromTemplate(tempfile, targetFileName);
                    }
                    finally
                    {
                        File.Delete(tempfile);
                    }
                }
            }

            if (open)
            {
                Window wnd = addedItem.Open(Constants.vsViewKindPrimary);
                wnd.Visible = true;
                wnd.Activate();
            }
        }
        private VsBoundReference GetReferenceTarget(string target, string recipeName)
        {
            VsBoundReference vsTarget = null;
            DTE dte = GetService <DTE>(true);

            target = DteHelper.ReplaceParameters(target, this.ReplacementDictionary);
            // Special case for "/" value.
            if (target.Equals("/") || target.Equals("\\"))
            {
                // "/" is the solution if we're in a solution template, the
                // project it this is a project template or the item if it's an item template.
                if (this.Project != null)
                {
                    vsTarget = new ProjectReference(recipeName, this.Project);
                }
                else if (this.Item != null)
                {
                    vsTarget = new ProjectItemReference(recipeName, this.Item);
                }
                else
                {
                    vsTarget = new SolutionReference(recipeName, dte.Solution);
                }
            }
            else if (template.VSKind == WizardRunKind.AsMultiProject)
            {
                string pathToTarget = target.Substring(1);
                if (root != null && root.Object is SolutionFolder)
                {
                    pathToTarget = DteHelper.BuildPath(root) + target;
                }
                ProjectItem prItem = DteHelper.FindItemByPath(dte.Solution, pathToTarget);
                if (prItem != null)
                {
                    vsTarget = new ProjectItemReference(recipeName, prItem);
                }
                else
                {
                    // Try finding a project.
                    Project prj = DteHelper.FindProjectByPath(dte.Solution, pathToTarget);
                    if (prj != null)
                    {
                        vsTarget = new ProjectReference(recipeName, prj);
                    }
                }
            }
            else if (template.VSKind == WizardRunKind.AsNewProject && this.Project != null)
            {
                ProjectItem prItem = DteHelper.FindItemByPath(dte.Solution,
                                                              DteHelper.BuildPath(this.Project) + target);
                // Can only refer to items.
                if (prItem != null)
                {
                    vsTarget = new ProjectItemReference(recipeName, prItem);
                }
            }
            else
            {
                // We got here because there's an Item template that contains an assetname other than "\".
                throw new ArgumentException(String.Format(
                                                CultureInfo.CurrentCulture,
                                                Properties.Resources.Templates_ItemTargetInvalid,
                                                Path.GetFileName(template.FileName), target), "Target");
            }
            return(vsTarget);
        }
예제 #14
0
 public string GetAppliesTo(object target)
 {
     return(DteHelper.BuildPath(((EnvDTE80.SolutionFolder)target).Parent));
 }
예제 #15
0
 public string GetSerializationData(object target)
 {
     return(DteHelper.BuildPath(((EnvDTE80.SolutionFolder)target).Parent));
 }
예제 #16
0
 public string GetAppliesTo(object target)
 {
     return(DteHelper.BuildPath(target));
 }
예제 #17
0
 public string GetSerializationData(object target)
 {
     return(DteHelper.BuildPath(target));
 }