Exemple #1
0
        public void OnBuildBegin(vsBuildScope Scope, vsBuildAction Action)
        {
            try
            {
                ThreadHelper.ThrowIfNotOnUIThread();
                var projectItemHelper = new ProjectItemRetreiver(GotoAsyncPackage.EnvDTE);
                var projectItems      = projectItemHelper.GetProjectItemsFromSolutionProjects();

                foreach (var xmlFile in DocumentHelper.GetXmlFiles(projectItems))
                {
                    var validator = XmlValidatorsAggregator.Create.AllValidatorsForBuild(xmlFile.FilePath);
                    validator.ValidateBuildDocument();
                    validator.AddToErrorList();
                }
            }
            catch (Exception ex)
            {
                LogManager.GetLogger("error").Error(ex, "BuildEvents.OnBuildBegin");
                OutputWindowLogger.WriteLn($"Exception occured during BuildEvents.OnBuildBegin: { ex.Message}");
            }
        }
        private static List <XmlFileInfo> GetFilesByExtension(IEnumerable <ProjectItem> projectItems, string extension)
        {
            Microsoft.VisualStudio.Shell.ThreadHelper.ThrowIfNotOnUIThread();

            var xmlFilesList = new List <XmlFileInfo>();

            bool needRefresh = false;

            foreach (var item in projectItems)
            {
                string fileName = null;
                try
                {
                    var hasCorrectExtension = item.Kind == EnvDTE.Constants.vsProjectItemKindPhysicalFile && item.FileCount == 1;
                    if (hasCorrectExtension)
                    {
                        fileName = item.FileNames[0];
                        if (Path.GetExtension(fileName).Equals(extension, StringComparison.CurrentCultureIgnoreCase))
                        {
                            xmlFilesList.Add(new XmlFileInfo
                            {
                                FilePath    = (string)item.Properties.Item("FullPath").Value,
                                ProjectName = item.ContainingProject.Name,
                            });
                        }
                    }
                }
                catch (Exception)
                {
                    //Ignore item
                }
            }
            if (needRefresh)
            {
                var test = new ProjectItemRetreiver(GotoAsyncPackage.EnvDTE);
                return(GetFilesByExtension(test.GetProjectItemsFromSolutionProjects(), extension));
            }
            return(xmlFilesList);
        }