コード例 #1
0
        public static void CleanupFiles(string[] projectNames, string[] extensions)
        {
            RetryUtil.RetryOnException(() =>
            {
                var cleanupItems = new List <ProjectItem>();

                foreach (var projectName in projectNames)
                {
                    var project = GetSolutionProjects().First(p => p.Name == projectName);

                    var items = GetAllProjectItemsRecursive(project.ProjectItems);

                    foreach (var extension in extensions)
                    {
                        cleanupItems.AddRange(items.Where(n => n.Name.EndsWith(extension)));
                    }
                }

                foreach (var item in cleanupItems)
                {
                    var fullPath = GetProjectItemFullPath(item);

                    item.Remove();

                    if (File.Exists(fullPath))
                    {
                        File.Delete(fullPath);
                    }
                }

                foreach (var projectName in projectNames)
                {
                    var projectPath = GetProjectDirectory(projectName);
                    foreach (var extension in extensions)
                    {
                        foreach (var file in Directory.EnumerateFiles(projectPath,
                                                                      $"*{extension}",
                                                                      SearchOption.AllDirectories))
                        {
                            File.Delete(file);
                        }
                    }
                }
            });
        }