Skip to content

Commit a046e81

Browse files
authored
Merge pull request #8 from reduckted/updates
Updates
2 parents 152d3ae + 0be690f commit a046e81

File tree

6 files changed

+56
-27
lines changed

6 files changed

+56
-27
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
1+
# 2.5.1 (2025-07-29)
2+
3+
- 🐛 Improved error handling when loading or unloading projects fails.
4+
15
# 2.5.0 (2023-12-23)
26

37
- ✨ Filtering options (load dependencies, use regular expressions, etc.) are now stored on a per-solution basis.
48
- ✨ The expanded state of nodes in the Project Filter dialog are remembered.
59

610
# 2.4.1 (2023-08-14)
711

8-
- 🐛 When using a Solution Filter (`.slnf`), projects would sometimes be hidden in Solution Explorer after they were loaded (#4).
12+
- 🐛 When using a Solution Filter (`.slnf`), projects would sometimes be hidden in Solution Explorer after they were loaded (#4).
913

1014
# 2.4.0 (2022-10-22)
1115

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project>
22

33
<PropertyGroup>
4-
<Version>2.5.0</Version>
4+
<Version>2.5.1</Version>
55
<TargetFramework>net48</TargetFramework>
66
<Nullable>enable</Nullable>
77
<LangVersion>10.0</LangVersion>

global.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"sdk": {
3-
"version": "9.0.200"
3+
"version": "9.0.302"
44
}
5-
}
5+
}

source/ProjectFilter/ProjectFilter.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,15 @@
8080
<PrivateAssets>all</PrivateAssets>
8181
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
8282
</PackageReference>
83-
<PackageReference Include="Community.VisualStudio.Toolkit.17" Version="17.0.527" />
83+
<PackageReference Include="Community.VisualStudio.Toolkit.17" Version="17.0.533" />
8484
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="9.0.0">
8585
<PrivateAssets>all</PrivateAssets>
8686
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
8787
</PackageReference>
8888
<PackageReference Include="Microsoft.VisualStudio.SDK" Version="17.0.32112.339" ExcludeAssets="runtime">
8989
<IncludeAssets>compile; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
9090
</PackageReference>
91-
<PackageReference Include="Microsoft.VSSDK.BuildTools" Version="17.13.2126">
91+
<PackageReference Include="Microsoft.VSSDK.BuildTools" Version="17.14.2094">
9292
<PrivateAssets>all</PrivateAssets>
9393
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
9494
</PackageReference>

source/ProjectFilter/Services/FilterService.cs

Lines changed: 42 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -137,19 +137,26 @@ private static async Task UnloadProjectAsync(Guid identifier, State state) {
137137

138138
if (IsLoaded(state.Solution, identifier)) {
139139
string name;
140-
int result;
141140

142141

143142
name = state.Solution.GetName(identifier);
144143
state.SetProgressText($"Unloading {name}...");
145144

146-
result = state.Solution.UnloadProject(
147-
identifier,
148-
(uint)_VSProjectUnloadStatus.UNLOADSTATUS_UnloadedByUser
149-
);
145+
try {
146+
int result;
147+
148+
149+
result = state.Solution.UnloadProject(
150+
identifier,
151+
(uint)_VSProjectUnloadStatus.UNLOADSTATUS_UnloadedByUser
152+
);
150153

151-
if (ErrorHandler.Failed(result)) {
152-
await LogFailureAsync($"Failed to unload project '{name}'.", result);
154+
if (ErrorHandler.Failed(result)) {
155+
await LogFailureAsync($"Failed to unload project '{name}'.", result);
156+
}
157+
158+
} catch (Exception ex) when (!ErrorHandler.IsCriticalException(ex)) {
159+
await LogFailureAsync($"Failed to unload project '{name}'.", ex);
153160
}
154161

155162
state.OnProjectUnloaded(identifier);
@@ -166,23 +173,33 @@ private static async Task LoadProjectAsync(Guid identifier, bool loadProjectDepe
166173
// visited it before, then we don't need to do anything this time.
167174
if (state.ProjectsVisitedWhileLoading.Add(identifier)) {
168175
IEnumerable<Guid>? dependencies;
169-
bool loaded;
176+
bool wasLoaded;
170177

171178

172179
dependencies = null;
173-
loaded = false;
180+
wasLoaded = false;
174181

175182
if (!IsLoaded(state.Solution, identifier)) {
176183
string name;
177-
int result;
178184

179185

180186
name = state.Solution.GetName(identifier);
181187
state.SetProgressText($"Loading {name}...");
182-
result = state.Solution.ReloadProject(identifier);
183188

184-
if (ErrorHandler.Failed(result)) {
185-
await LogFailureAsync($"Failed to load project '{name}'.", result);
189+
try {
190+
int result;
191+
192+
193+
result = state.Solution.ReloadProject(identifier);
194+
195+
if (ErrorHandler.Failed(result)) {
196+
await LogFailureAsync($"Failed to load project '{name}'.", result);
197+
return;
198+
}
199+
200+
} catch (Exception ex) when (!ErrorHandler.IsCriticalException(ex)) {
201+
await LogFailureAsync($"Failed to load project '{name}'.", ex);
202+
return;
186203
}
187204

188205
// Don't record that we've loaded the project _yet_. If we do that
@@ -193,7 +210,7 @@ private static async Task LoadProjectAsync(Guid identifier, bool loadProjectDepe
193210
// the progress will increase to 100% and then immediately decrease.
194211
// We'll wait until we've recorded that the dependencies need to be
195212
// loaded before we record that this project was loaded.
196-
loaded = true;
213+
wasLoaded = true;
197214

198215
// Whenever a project is loaded, we should recalculate project dependencies
199216
// to ensure that the new project's dependencies are correct.
@@ -219,7 +236,7 @@ private static async Task LoadProjectAsync(Guid identifier, bool loadProjectDepe
219236
// if we actually loaded the given project, then we can record that
220237
// it has been loaded. This prevents the progress from increasing
221238
// and then decreasing (instead, it will decrease and then increase).
222-
if (loaded) {
239+
if (wasLoaded) {
223240
state.OnProjectLoaded(identifier);
224241
}
225242

@@ -357,13 +374,21 @@ private static async Task<IEnumerable<Guid>> GetProjectsToCollapseAsync(ISolutio
357374
}
358375

359376

360-
private static async Task LogFailureAsync(string message, int result) {
377+
private static Task LogFailureAsync(string message, int result) {
378+
return LogFailureAsync(message, Marshal.GetExceptionForHR(result));
379+
}
380+
381+
382+
private static async Task LogFailureAsync(string message, Exception? ex) {
361383
ILogger logger;
384+
string exceptionMessage;
362385

363386

364387
logger = await VS.GetRequiredServiceAsync<ILogger, ILogger>();
365388

366-
await logger.WriteLineAsync($"{message} {Marshal.GetExceptionForHR(result).Message}");
389+
exceptionMessage = ex?.Message ?? "[Unknown Error]";
390+
391+
await logger.WriteLineAsync($"{message} {exceptionMessage}");
367392
}
368393

369394
}

tests/ProjectFilter.UnitTests/ProjectFilter.UnitTests.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
44
<RootNamespace>ProjectFilter</RootNamespace>
55
<IsPackable>false</IsPackable>
66
</PropertyGroup>
77

88
<ItemGroup>
9-
<PackageReference Include="Community.VisualStudio.Toolkit.17" Version="17.0.527" />
9+
<PackageReference Include="Community.VisualStudio.Toolkit.17" Version="17.0.533" />
1010
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="9.0.0">
1111
<PrivateAssets>all</PrivateAssets>
1212
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1313
</PackageReference>
14-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
14+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.14.1" />
1515
<PackageReference Include="Microsoft.VisualStudio.SDK" Version="17.0.32112.339" />
1616
<PackageReference Include="Microsoft.VisualStudio.Sdk.TestFramework" Version="17.2.7" />
1717
<PackageReference Include="Microsoft.VisualStudio.Sdk.TestFramework.Xunit" Version="17.2.7" />
18-
<PackageReference Include="NSubstitute" Version="5.1.0" />
18+
<PackageReference Include="NSubstitute" Version="5.3.0" />
1919
<PackageReference Include="xunit" Version="2.6.3" />
2020
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.5">
2121
<PrivateAssets>all</PrivateAssets>

0 commit comments

Comments
 (0)