From 286c084dece0024f4435c13f044cbeb2c1f47643 Mon Sep 17 00:00:00 2001 From: Tony Hallett Date: Wed, 4 Dec 2024 11:14:08 +0000 Subject: [PATCH] use project properties for assembly name --- SharedProject/Core/Model/CoverageProject.cs | 42 ++++++++++++++++++--- 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/SharedProject/Core/Model/CoverageProject.cs b/SharedProject/Core/Model/CoverageProject.cs index 2e9a211..7e648e9 100644 --- a/SharedProject/Core/Model/CoverageProject.cs +++ b/SharedProject/Core/Model/CoverageProject.cs @@ -307,7 +307,7 @@ private async Task> SafeGetReferencedProjectsFromDteAsyn return null; } - private async Task> GetReferencedProjectsFromDteAsync() + private async Task GetProjectAsync() { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); var project = dte.Solution.Projects.Cast().FirstOrDefault(p => @@ -328,12 +328,42 @@ private async Task> GetReferencedProjectsFromDteAsync() return null; } - var vsproject = project.Object as VSLangProj.VSProject; - return vsproject.References.Cast().Where(r => r.SourceProject != null).Select(r => + return project.Object as VSLangProj.VSProject; + } + + private IEnumerable GetReferencedSourceProjects(VSLangProj.VSProject vsproject) + { + return vsproject.References.Cast().Where(r => r.SourceProject != null) + .Select(r => r.SourceProject); + } + + private async Task GetAssemblyNameAsync(Project project) + { + await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); + var assNameProperty = project.Properties.Cast().FirstOrDefault(p => { - ThreadHelper.ThrowIfNotOnUIThread(); - return new ReferencedProject(r.SourceProject.FullName, r.Name); - }).ToList(); +#pragma warning disable VSTHRD010 // Invoke single-threaded types on Main thread + return p.Name == "AssemblyName"; +#pragma warning restore VSTHRD010 // Invoke single-threaded types on Main thread + }); + return assNameProperty?.Value.ToString() ?? project.Name; + } + private async Task GetReferencedProjectAsync(Project project) + { + await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); + var assemblyName = await GetAssemblyNameAsync(project); + return new ReferencedProject(project.FullName, assemblyName); + } + + private async Task> GetReferencedProjectsFromDteAsync() + { + var vsproject = await GetProjectAsync(); + + if (vsproject == null) + { + return null; + } + return (await Task.WhenAll(GetReferencedSourceProjects(vsproject).Select(GetReferencedProjectAsync))).ToList(); }