diff --git a/src/CodingWithCalvin.SuperClean/Commands/SuperCleanCommand.cs b/src/CodingWithCalvin.SuperClean/Commands/SuperCleanCommand.cs index a0716b8..bbef494 100644 --- a/src/CodingWithCalvin.SuperClean/Commands/SuperCleanCommand.cs +++ b/src/CodingWithCalvin.SuperClean/Commands/SuperCleanCommand.cs @@ -86,7 +86,7 @@ private static async Task OpenPathAsync(object sender, EventArgs e) case SolutionItemType.Solution: try { - var (success, errors) = await SuperCleanSolution(); + var (success, errors, skippedWebsites) = await SuperCleanSolution(); if (!success) { @@ -94,6 +94,16 @@ private static async Task OpenPathAsync(object sender, EventArgs e) } VsixTelemetry.LogInformation("Solution super cleaned successfully"); + + if (skippedWebsites.Count > 0) + { + MessageBox.Show( + $"Super Clean skipped the following Web Site project(s) because their bin folder is required at runtime:{Environment.NewLine}{Environment.NewLine} • {string.Join($"{Environment.NewLine} • ", skippedWebsites)}", + "Super Clean", + System.Windows.Forms.MessageBoxButtons.OK, + System.Windows.Forms.MessageBoxIcon.Information + ); + } } catch (Exception ex) { @@ -116,8 +126,23 @@ Unable to Super Clean solution case SolutionItemType.Project: try { - SuperCleanProject(activeItem); - VsixTelemetry.LogInformation("Project super cleaned successfully"); + var cleaned = await SuperCleanProjectAsync(activeItem); + + if (cleaned) + { + VsixTelemetry.LogInformation("Project super cleaned successfully"); + } + else + { + VsixTelemetry.LogInformation($"Project skipped: {activeItem.Name}"); + + MessageBox.Show( + $"Super Clean skipped \"{activeItem.Name}\" because Web Site projects rely on their bin folder at runtime.", + "Super Clean", + System.Windows.Forms.MessageBoxButtons.OK, + System.Windows.Forms.MessageBoxIcon.Information + ); + } } catch (Exception ex) { @@ -139,20 +164,27 @@ Unable to Super Clean project ${activeItem.Name} break; } - async Task<(bool, string)> SuperCleanSolution() + async Task<(bool, string, List)> SuperCleanSolution() { using var solutionActivity = VsixTelemetry.StartCommandActivity("SuperClean.SuperCleanSolution"); var success = true; var errors = new StringBuilder(); var projectCount = 0; + var skippedWebsites = new List(); foreach (var project in await VS.Solutions.GetAllProjectsAsync()) { try { - SuperCleanProject(project); - projectCount++; + if (await SuperCleanProjectAsync(project)) + { + projectCount++; + } + else + { + skippedWebsites.Add(project.Name); + } } catch (Exception ex) { @@ -163,16 +195,25 @@ Unable to Super Clean project ${activeItem.Name} } solutionActivity?.SetTag("projects.cleaned", projectCount); + solutionActivity?.SetTag("projects.skipped", skippedWebsites.Count); solutionActivity?.SetTag("success", success); - return (success, errors.ToString()); + return (success, errors.ToString(), skippedWebsites); } - void SuperCleanProject(SolutionItem project) + async Task SuperCleanProjectAsync(SolutionItem project) { using var projectActivity = VsixTelemetry.StartCommandActivity("SuperClean.SuperCleanProject"); - var projectPath = + if (project is Project typedProject && await typedProject.IsKindAsync(ProjectTypes.WEBSITE)) + { + projectActivity?.SetTag("skipped", true); + projectActivity?.SetTag("skip.reason", "website-project"); + VsixTelemetry.LogInformation($"Skipped Web Site project: {project.Name}"); + return false; + } + + var projectPath = Path.GetDirectoryName(project.FullPath) ?? throw new InvalidOperationException(); @@ -190,6 +231,8 @@ void SuperCleanProject(SolutionItem project) Directory.Delete(objPath, true); projectActivity?.SetTag("obj.deleted", true); } + + return true; } } }