Пример #1
0
        private void ProjectSync(EnvDTE.ProjectItem templateProjectItem, IEnumerable <OutputFile> keepFileNames)
        {
            var groupedFileNames = from f in keepFileNames
                                   group f by new { f.ProjectName, f.FolderName }
            into l
                select new
            {
                ProjectName = l.Key.ProjectName,
                FolderName  = l.Key.FolderName,
                FirstItem   = l.First(),
                OutputFiles = l
            };

            this.templatePlaceholderList.Clear();

            foreach (var item in groupedFileNames)
            {
                EnvDTE.ProjectItem pi = VSHelper.GetTemplateProjectItem(templateProjectItem.DTE, item.FirstItem, templateProjectItem);
                ProjectSyncPart(pi, item.OutputFiles);

                if (pi.Name.EndsWith("txt4"))
                {
                    this.templatePlaceholderList.Add(VSHelper.GetProjectItemFullPath(pi));
                }
            }

            // clean up
            bool hasDefaultItems = groupedFileNames.Where(f => String.IsNullOrEmpty(f.ProjectName) && String.IsNullOrEmpty(f.FolderName)).Count() > 0;

            if (hasDefaultItems == false)
            {
                ProjectSyncPart(templateProjectItem, new List <OutputFile>());
            }
        }
Пример #2
0
        /// <summary>
        /// Removes old template placeholders from the solution.
        /// </summary>
        private void CleanUpTemplatePlaceholders()
        {
            string[] activeTemplateFullNames    = this.templatePlaceholderList.ToArray();
            string[] allHelperTemplateFullNames = VSHelper.GetAllSolutionItems(this.dte)
                                                  .Where(p => p.Name == VSHelper.GetTemplatePlaceholderName(this.templateProjectItem))
                                                  .Select(p => VSHelper.GetProjectItemFullPath(p))
                                                  .ToArray();

            var delta = allHelperTemplateFullNames.Except(activeTemplateFullNames).ToArray();

            var dirtyHelperTemplates = VSHelper.GetAllSolutionItems(this.dte)
                                       .Where(p => delta.Contains(VSHelper.GetProjectItemFullPath(p)));

            foreach (ProjectItem item in dirtyHelperTemplates)
            {
                if (item.ProjectItems != null)
                {
                    foreach (ProjectItem subItem in item.ProjectItems)
                    {
                        subItem.Remove();
                    }
                }

                item.Remove();
            }
        }