From 71678cff8e52caed30e43c039c40c93f06374cb2 Mon Sep 17 00:00:00 2001 From: "Calvin A. Allen" Date: Thu, 11 Dec 2025 16:07:43 -0500 Subject: [PATCH] Fix file path resolution for unloaded projects When a project is unloaded in Solution Explorer, project.FullName returns an empty string. This change detects unloaded projects by checking the project.Kind against the unloaded project GUID, then falls back to constructing the path from the solution directory and project.UniqueName. --- .../Helpers/ProjectHelpers.cs | 31 ++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/src/CodingWithCalvin.OpenInNotepadPlusPlus/Helpers/ProjectHelpers.cs b/src/CodingWithCalvin.OpenInNotepadPlusPlus/Helpers/ProjectHelpers.cs index f7c10aa..d30b415 100644 --- a/src/CodingWithCalvin.OpenInNotepadPlusPlus/Helpers/ProjectHelpers.cs +++ b/src/CodingWithCalvin.OpenInNotepadPlusPlus/Helpers/ProjectHelpers.cs @@ -1,4 +1,5 @@ using System; +using System.IO; using EnvDTE; using EnvDTE80; using Microsoft.VisualStudio.Shell; @@ -7,6 +8,8 @@ namespace CodingWithCalvin.OpenInNotepadPlusPlus.Helpers { internal static class ProjectHelpers { + private const string UnloadedProjectGuid = "{67294A52-A4F0-11D2-AA88-00C04F688DDE}"; + public static string GetSelectedPath(DTE2 dte) { ThreadHelper.ThrowIfNotOnUIThread(); @@ -21,12 +24,38 @@ UIHierarchyItem selectedItem in (Array) case ProjectItem projectItem: return projectItem.FileNames[1]; case Project project: - return project.FullName; + return GetProjectPath(project, dte.Solution); case Solution solution: return solution.FullName; } } return null; } + + private static string GetProjectPath(Project project, Solution solution) + { + ThreadHelper.ThrowIfNotOnUIThread(); + + bool isUnloaded = project.Kind.Equals(UnloadedProjectGuid, StringComparison.OrdinalIgnoreCase); + + if (!isUnloaded) + { + return project.FullName; + } + + // For unloaded projects, FullName is empty but UniqueName contains + // the relative path from the solution directory + if (!string.IsNullOrEmpty(project.UniqueName) && !string.IsNullOrEmpty(solution?.FullName)) + { + var solutionDirectory = Path.GetDirectoryName(solution.FullName); + var projectPath = Path.Combine(solutionDirectory, project.UniqueName); + if (File.Exists(projectPath)) + { + return projectPath; + } + } + + return null; + } } }