Skip to content

Commit 7bbd75c

Browse files
authored
fix(commands): skip Web Site projects when cleaning (#32)
* fix(commands): skip Web Site projects when cleaning For legacy Web Site Projects (project type GUID {E24C65DC-7377-472B-9ABA-BC803B73C61A}) the bin folder is not a build output; it contains assemblies that are integral to the project. Detect these via Project.IsKindAsync(ProjectTypes.WEBSITE) and skip them. * feat(commands): notify user when Web Site projects are skipped Show a single summary MessageBox after a solution-level Super Clean listing any skipped Web Site projects, and a dedicated MessageBox when Super Clean is invoked directly on a Web Site project so the user understands why nothing was cleaned.
1 parent 905361e commit 7bbd75c

1 file changed

Lines changed: 52 additions & 9 deletions

File tree

src/CodingWithCalvin.SuperClean/Commands/SuperCleanCommand.cs

Lines changed: 52 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,24 @@ private static async Task OpenPathAsync(object sender, EventArgs e)
8686
case SolutionItemType.Solution:
8787
try
8888
{
89-
var (success, errors) = await SuperCleanSolution();
89+
var (success, errors, skippedWebsites) = await SuperCleanSolution();
9090

9191
if (!success)
9292
{
9393
throw new ApplicationException(errors);
9494
}
9595

9696
VsixTelemetry.LogInformation("Solution super cleaned successfully");
97+
98+
if (skippedWebsites.Count > 0)
99+
{
100+
MessageBox.Show(
101+
$"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)}",
102+
"Super Clean",
103+
System.Windows.Forms.MessageBoxButtons.OK,
104+
System.Windows.Forms.MessageBoxIcon.Information
105+
);
106+
}
97107
}
98108
catch (Exception ex)
99109
{
@@ -116,8 +126,23 @@ Unable to Super Clean solution
116126
case SolutionItemType.Project:
117127
try
118128
{
119-
SuperCleanProject(activeItem);
120-
VsixTelemetry.LogInformation("Project super cleaned successfully");
129+
var cleaned = await SuperCleanProjectAsync(activeItem);
130+
131+
if (cleaned)
132+
{
133+
VsixTelemetry.LogInformation("Project super cleaned successfully");
134+
}
135+
else
136+
{
137+
VsixTelemetry.LogInformation($"Project skipped: {activeItem.Name}");
138+
139+
MessageBox.Show(
140+
$"Super Clean skipped \"{activeItem.Name}\" because Web Site projects rely on their bin folder at runtime.",
141+
"Super Clean",
142+
System.Windows.Forms.MessageBoxButtons.OK,
143+
System.Windows.Forms.MessageBoxIcon.Information
144+
);
145+
}
121146
}
122147
catch (Exception ex)
123148
{
@@ -139,20 +164,27 @@ Unable to Super Clean project ${activeItem.Name}
139164
break;
140165
}
141166

142-
async Task<(bool, string)> SuperCleanSolution()
167+
async Task<(bool, string, List<string>)> SuperCleanSolution()
143168
{
144169
using var solutionActivity = VsixTelemetry.StartCommandActivity("SuperClean.SuperCleanSolution");
145170

146171
var success = true;
147172
var errors = new StringBuilder();
148173
var projectCount = 0;
174+
var skippedWebsites = new List<string>();
149175

150176
foreach (var project in await VS.Solutions.GetAllProjectsAsync())
151177
{
152178
try
153179
{
154-
SuperCleanProject(project);
155-
projectCount++;
180+
if (await SuperCleanProjectAsync(project))
181+
{
182+
projectCount++;
183+
}
184+
else
185+
{
186+
skippedWebsites.Add(project.Name);
187+
}
156188
}
157189
catch (Exception ex)
158190
{
@@ -163,16 +195,25 @@ Unable to Super Clean project ${activeItem.Name}
163195
}
164196

165197
solutionActivity?.SetTag("projects.cleaned", projectCount);
198+
solutionActivity?.SetTag("projects.skipped", skippedWebsites.Count);
166199
solutionActivity?.SetTag("success", success);
167200

168-
return (success, errors.ToString());
201+
return (success, errors.ToString(), skippedWebsites);
169202
}
170203

171-
void SuperCleanProject(SolutionItem project)
204+
async Task<bool> SuperCleanProjectAsync(SolutionItem project)
172205
{
173206
using var projectActivity = VsixTelemetry.StartCommandActivity("SuperClean.SuperCleanProject");
174207

175-
var projectPath =
208+
if (project is Project typedProject && await typedProject.IsKindAsync(ProjectTypes.WEBSITE))
209+
{
210+
projectActivity?.SetTag("skipped", true);
211+
projectActivity?.SetTag("skip.reason", "website-project");
212+
VsixTelemetry.LogInformation($"Skipped Web Site project: {project.Name}");
213+
return false;
214+
}
215+
216+
var projectPath =
176217
Path.GetDirectoryName(project.FullPath)
177218
?? throw new InvalidOperationException();
178219

@@ -190,6 +231,8 @@ void SuperCleanProject(SolutionItem project)
190231
Directory.Delete(objPath, true);
191232
projectActivity?.SetTag("obj.deleted", true);
192233
}
234+
235+
return true;
193236
}
194237
}
195238
}

0 commit comments

Comments
 (0)