/// <summary>
        /// Enumerates all items in the project except those in the "Reference" group.
        /// </summary>
        /// <param name="project">The project from which to retrieve the items.</param>
        /// <returns>A list of item "Include" values.  For items that specify files, these will be the file names.</returns>
        /// <exception cref="System.ArgumentNullException">Thrown if <c>project</c> is null.</exception>
        public IEnumerable <string> AllItemsInProject(IVsProject project)
        {
            if (project == null)
            {
                throw new ArgumentNullException("project");
            }

            string       projectDir = Path.GetDirectoryName(ProjectUtilities.GetProjectFilePath(project));
            IVsHierarchy hierarchy  = project as IVsHierarchy;

            return
                (ChildrenOf(hierarchy, VSConstants.VSITEMID.Root)
                 .Select(
                     id =>
            {
                string name = null;
                project.GetMkDocument((uint)id, out name);
                if (name != null && name.Length > 0 && !Path.IsPathRooted(name))
                {
                    name = Utilities.AbsolutePathFromRelative(name, projectDir);
                }
                return name;
            })
                 .Where(File.Exists));
        }
        /// <summary>
        /// Enumerates all items in the project except those in the "Reference" group.
        /// </summary>
        /// <param name="project">The project from which to retrieve the items.</param>
        /// <returns>A list of item "Include" values.  For items that specify files, these will be the file names.</returns>
        /// <exception cref="System.ArgumentNullException">Thrown if <c>project</c> is null.</exception>
        public ICollection <string> AllItemsInProject(IVsProject project)
        {
            if (project == null)
            {
                throw new ArgumentNullException("project");
            }

            string       projectDir = Path.GetDirectoryName(ProjectUtilities.GetProjectFilePath(project));
            IVsHierarchy hierarchy  = project as IVsHierarchy;

            List <string> allNames = ChildrenOf(hierarchy, HierarchyConstants.VSITEMID_ROOT).ConvertAll <string>(
                delegate(uint id)
            {
                string name = null;
                project.GetMkDocument(id, out name);
                if (name != null && name.Length > 0 && !Path.IsPathRooted(name))
                {
                    name = Utilities.AbsolutePathFromRelative(name, projectDir);
                }
                return(name);
            });

            allNames.RemoveAll(
                delegate(string name)
            {
                return(!File.Exists(name));
            });

            return(allNames);
        }
        private void ReadConfigFromProject()
        {
            string  projectFolder = Path.GetDirectoryName(ProjectUtilities.GetProjectFilePath(_project));
            Project dteProject    = GetDTEProject(_project);

            if (dteProject.Globals.get_VariableExists(_termTablesName))
            {
                string termTables = (string)dteProject.Globals[_termTablesName];

                foreach (string table in termTables.Split(';'))
                {
                    if (table != null && table.Length > 0)
                    {
                        if (Path.IsPathRooted(table))
                        {
                            _termTableFiles.Add(table);
                        }
                        else
                        {
                            _termTableFiles.Add(Utilities.AbsolutePathFromRelative(table, projectFolder));
                        }
                    }
                }
            }

            if (dteProject.Globals.get_VariableExists(_ignoreInstancesName))
            {
                string ignoreInstances = (string)dteProject.Globals[_ignoreInstancesName];
                _ignoreInstances.AddRange(BuildTask.Factory.DeserializeIgnoreInstances(ignoreInstances, projectFolder));
            }
        }
        void PersistIgnoreInstances()
        {
            string projectFolder = Path.GetDirectoryName(ProjectUtilities.GetProjectFilePath(_project));
            string serialization = BuildTask.Factory.SerializeIgnoreInstances(_ignoreInstances, projectFolder);

            CreateBuildTaskIfNecessary();
            _buildTask.SetParameter("IgnoreInstances", serialization);
        }
        void PersistTermTables()
        {
            CreateBuildTaskIfNecessary();

            string        projectFolder = Path.GetDirectoryName(ProjectUtilities.GetProjectFilePath(_project));
            List <string> relativePaths = Utilities.RelativizePathsIfPossible(_termTableFiles, projectFolder);

            _buildTask.SetParameter("TermTables", Utilities.Concatenate(relativePaths, ";"));
        }
        private void PersistIgnoreInstances()
        {
            string projectFolder = Path.GetDirectoryName(ProjectUtilities.GetProjectFilePath(_project));
            string serialization = BuildTask.Factory.SerializeIgnoreInstances(_ignoreInstances, projectFolder);

            Project dteProject = GetDTEProject(_project);

            dteProject.Globals[_ignoreInstancesName] = serialization;
            dteProject.Globals.set_VariablePersists(_ignoreInstancesName, true);
        }
        private void PersistTermTables()
        {
            string        projectFolder = Path.GetDirectoryName(ProjectUtilities.GetProjectFilePath(_project));
            List <string> relativePaths = Utilities.RelativizePathsIfPossible(_termTableFiles, projectFolder);

            Project dteProject = GetDTEProject(_project);

            dteProject.Globals[_termTablesName] = Utilities.Concatenate(relativePaths, ";");
            dteProject.Globals.set_VariablePersists(_termTablesName, true);
        }
        private static bool AllAreMSBuildProjects(IList <IVsProject> projects)
        {
            foreach (IVsProject project in projects)
            {
                if (!ProjectUtilities.IsMSBuildProject(project))
                {
                    return(false);
                }
            }

            return(true);
        }
        private Project GetDTEProject(IVsProject project)
        {
            string projectPath = ProjectUtilities.GetProjectFilePath(project);

            DTE dte = _serviceProvider.GetService(typeof(DTE)) as DTE;

            foreach (Project dteProject in dte.Solution.Projects)
            {
                if (String.Compare(dteProject.FileName, projectPath, StringComparison.OrdinalIgnoreCase) == 0)
                {
                    return(dteProject);
                }
            }

            return(null);
        }
        private static void CreateTaskIfNecessary(IVsProject project)
        {
            Project msbuildProject      = MSBuildProjectFromIVsProject(project);
            ProjectTargetElement target = msbuildProject.Xml.Targets.FirstOrDefault(element => element.Name == "AfterBuild");

            if (target == null)
            {
                target = msbuildProject.Xml.AddTarget("AfterBuild");
            }


            string importFolder       = Path.GetDirectoryName(typeof(CodeSweep.BuildTask.ScannerTask).Module.FullyQualifiedName);
            string importPath         = Utilities.EncodeProgramFilesVar(importFolder) + "\\CodeSweep.targets";
            string installedCondition = "Exists('" + importPath + "')";

            if (GetNamedTask(target, "ScannerTask") == null)
            {
                string             projectFolder = Path.GetDirectoryName(ProjectUtilities.GetProjectFilePath(project));
                ProjectTaskElement newTask       = target.AddTask("ScannerTask");
                newTask.Condition       = installedCondition + " and '$(" + RunWithBuildFlag + ")' == 'true'";
                newTask.ContinueOnError = "false";
                newTask.SetParameter("FilesToScan", CodeSweep.Utilities.Concatenate(AllItemGroupsInProject(msbuildProject.Xml), ";"));
                newTask.SetParameter("TermTables", Utilities.RelativePathFromAbsolute(Globals.DefaultTermTablePath, Path.GetDirectoryName(msbuildProject.FullPath)));
                newTask.SetParameter("Project", "$(MSBuildProjectFullPath)");
            }

            bool found = false;

            foreach (ProjectImportElement import in msbuildProject.Xml.Imports)
            {
                if (import.Project == importPath)
                {
                    found = true;
                    break;
                }
            }

            if (!found)
            {
                ProjectImportElement importElement = msbuildProject.Xml.AddImport(importPath);
                importElement.Condition = installedCondition;
            }
        }
        private void ReadConfigFromBuildTask()
        {
            string projectFolder = Path.GetDirectoryName(ProjectUtilities.GetProjectFilePath(_project));

            _ignoreInstances.AddRange(BuildTask.Factory.DeserializeIgnoreInstances(_buildTask.GetParameter("IgnoreInstances"), projectFolder));

            foreach (string termTable in _buildTask.GetParameter("TermTables").Split(';'))
            {
                if (termTable != null && termTable.Length > 0)
                {
                    if (Path.IsPathRooted(termTable))
                    {
                        _termTableFiles.Add(termTable);
                    }
                    else
                    {
                        _termTableFiles.Add(Utilities.AbsolutePathFromRelative(termTable, projectFolder));
                    }
                }
            }
        }
示例#12
0
        public int OnBeforeCloseProject(IVsHierarchy pHierarchy, int fRemoved)
        {
            string projFile = ProjectUtilities.GetProjectFilePath(pHierarchy as IVsProject);

            if (!string.IsNullOrEmpty(projFile))
            {
                // Remove all tasks for the project that is being closed.
                for (int i = 0; i < _tasks.Count; ++i)
                {
                    if (_tasks[i].ProjectFile == projFile)
                    {
                        _tasks.RemoveAt(i);
                        --i;
                    }
                }

                Refresh();
            }

            return(VSConstants.S_OK);
        }
        public static IProjectConfigurationStore GetProjectConfigurationStore(IVsProject project)
        {
            if (_projectStores.ContainsKey(project))
            {
                return(_projectStores[project]);
            }
            else
            {
                IProjectConfigurationStore store;

                if (ProjectUtilities.IsMSBuildProject(project))
                {
                    store = new ProjectConfigStore(project);
                }
                else
                {
                    store = new NonMSBuildProjectConfigStore(project, _serviceProvider);
                }

                _projectStores.Add(project, store);
                return(store);
            }
        }
示例#14
0
        public int GetColumnValue(int iField, out uint ptvtType, out uint ptvfFlags, out object pvarValue, out string pbstrAccessibilityName)
        {
            ptvfFlags = 0;
            pbstrAccessibilityName = "";

            switch ((TaskFields)iField)
            {
            case TaskFields.Class:
                ptvtType  = (uint)__VSTASKVALUETYPE.TVT_TEXT;
                pvarValue = _class;
                break;

            case TaskFields.Comment:
                ptvtType  = (uint)__VSTASKVALUETYPE.TVT_LINKTEXT;
                pvarValue = _comment;
                break;

            case TaskFields.File:
                ptvtType  = (uint)__VSTASKVALUETYPE.TVT_TEXT;
                ptvfFlags = (uint)__VSTASKVALUEFLAGS.TVF_FILENAME;
                pvarValue = _file;
                break;

            case TaskFields.Line:
                if (_line == -1)
                {
                    ptvtType  = (uint)__VSTASKVALUETYPE.TVT_NULL;
                    pvarValue = null;
                }
                else
                {
                    ptvtType  = (uint)__VSTASKVALUETYPE.TVT_BASE10;
                    pvarValue = _line + 1;     // Display as one-based coordinate.
                }
                break;

            case TaskFields.Priority:
                ptvfFlags = (uint)__VSTASKVALUEFLAGS.TVF_HORZ_CENTER;
                ptvtType  = (uint)__VSTASKVALUETYPE.TVT_IMAGE;
                pvarValue = TaskProvider.GetImageIndexForSeverity(_severity);
                if (_severity <= 1)
                {
                    pbstrAccessibilityName = Resources.HighPriority;
                }
                else if (_severity == 2)
                {
                    pbstrAccessibilityName = Resources.MediumPriority;
                }
                else
                {
                    pbstrAccessibilityName = Resources.LowPriority;
                }
                break;

            case TaskFields.PriorityNumber:
                ptvtType  = (uint)__VSTASKVALUETYPE.TVT_BASE10;
                pvarValue = _severity;
                break;

            case TaskFields.Project:
                ptvtType = (uint)__VSTASKVALUETYPE.TVT_TEXT;
                if (_projectFile != null && _projectFile.Length > 0)
                {
                    pvarValue = ProjectUtilities.GetUniqueProjectNameFromFile(_projectFile);
                }
                else
                {
                    pvarValue = "";
                }
                break;

            case TaskFields.Replacement:
                ptvtType  = (uint)__VSTASKVALUETYPE.TVT_TEXT;
                pvarValue = _replacement;
                break;

            case TaskFields.Term:
                ptvtType  = (uint)__VSTASKVALUETYPE.TVT_TEXT;
                pvarValue = _term;
                break;

            default:
                ptvtType  = (uint)__VSTASKVALUETYPE.TVT_NULL;
                pvarValue = null;
                return(VSConstants.E_INVALIDARG);
            }

            if (Ignored)
            {
                ptvfFlags |= (uint)__VSTASKVALUEFLAGS.TVF_STRIKETHROUGH;
            }

            return(VSConstants.S_OK);
        }
示例#15
0
        void GatherProjectInfo(IEnumerable <IVsProject> projects)
        {
            _projectsToScan.Clear();
            _totalFiles = 0;

            foreach (IVsProject project in projects)
            {
                List <string> filesToScan    = new List <string>();
                List <string> termTableFiles = new List <string>();

                if (Factory.GetProjectConfigurationStore(project).HasConfiguration)
                {
                    filesToScan.AddRange(Factory.GetBuildManager().AllItemsInProject(project));
                    termTableFiles.AddRange(Factory.GetProjectConfigurationStore(project).TermTableFiles);
                    _totalFiles += (uint)filesToScan.Count;
                }

                _projectsToScan.Add(new ProjectConfiguration(filesToScan, termTableFiles, ProjectUtilities.GetProjectFilePath(project)));
            }
        }
 /// <summary>
 /// This function is the callback used to execute a command when the a menu item is clicked.
 /// </summary>
 private void MenuItemCallback(object sender, EventArgs e)
 {
     Factory.GetDialog().Invoke(ProjectUtilities.GetProjectsOfCurrentSelections());
 }
 private static Project MSBuildProjectFromIVsProject(IVsProject project)
 {
     return(ProjectCollection.GlobalProjectCollection.GetLoadedProjects(ProjectUtilities.GetProjectFilePath(project)).FirstOrDefault());
 }