From ed66a1197e2646472816184f51c5c156614e85b9 Mon Sep 17 00:00:00 2001 From: Rami Date: Thu, 7 Nov 2024 17:50:28 -0800 Subject: [PATCH] Fixed issue where the extension would create multiple output window panes Fixed issue where exceptions were not being written to the output window pane Fixed issue when trying to get the file name of unloaded projects --- .github/workflows/build.yml | 5 ++--- CHANGELOG.md | 6 ++++++ .../Logging/CustomLoggerProvider.cs | 14 +++++++++++++- .../Logging/OutputWindowLogger.cs | 4 ++++ .../Package.cs | 1 + .../Services/ProjectService.cs | 14 +++++++++++++- 6 files changed, 39 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index badb3b8..ab5e26f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -150,11 +150,10 @@ jobs: uses: actions/upload-artifact@v4 # https://github.com/marketplace/actions/upload-a-build-artifact with: - name: PackageReferenceVersionToAttributeExtension-${{ env.VERSION }} ${{matrix.Configuration}} + name: PackageReferenceVersionToAttribute-${{ env.VERSION }} ${{matrix.Configuration}} path: | .\src\PackageReferenceVersionToAttributeExtension\bin\${{matrix.Configuration}}\PackageReferenceVersionToAttributeExtension.vsix .\src\PackageReferenceVersionToAttributeTool\bin\${{matrix.Configuration}}\PackageReferenceVersionToAttribute.Tool.${{ env.SEM_VERSION }}.nupkg - if-no-files-found: error - name: Publish GitHub Release if: ${{ matrix.Configuration == 'Release' && github.event.inputs.publishVsix == 'true' }} @@ -174,7 +173,7 @@ jobs: run: dotnet nuget push .\src\PackageReferenceVersionToAttributeTool\bin\${{matrix.Configuration}}\PackageReferenceVersionToAttribute.Tool.${{ env.SEM_VERSION }}.nupkg --api-key ${{ secrets.NUGET_KEY }} --source https://api.nuget.org/v3/index.json - name: Publish to Open VSIX - if: ${{ matrix.Configuration == 'Release' && github.event_name != 'pull_request' && (github.event.inputs.skipPublishNupkg == '' || github.event.inputs.skipPublishNupkg == 'false') }} + if: ${{ matrix.Configuration == 'Release' && github.event_name != 'pull_request' && (github.event.inputs.publishVsix == 'true') }} run: | [Reflection.Assembly]::LoadWithPartialName("System.Web") | Out-Null $vsixFile = ".\src\PackageReferenceVersionToAttributeExtension\bin\${{matrix.Configuration}}\PackageReferenceVersionToAttributeExtension.vsix" diff --git a/CHANGELOG.md b/CHANGELOG.md index ef9d8d2..39ef514 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Change Log +## v1.0.1108.39 (November 8th, 2024) + +- Fixed issue where the extension would create multiple output window panes +- Fixed issue where exceptions were not being written to the output window pane +- Fixed issue when trying to get the file name of unloaded projects + ## v1.0.1105.37 (November 5th, 2024) - Added support for converting projects within sln files on the command line diff --git a/src/PackageReferenceVersionToAttributeExtension/Logging/CustomLoggerProvider.cs b/src/PackageReferenceVersionToAttributeExtension/Logging/CustomLoggerProvider.cs index dba2aef..93eae6b 100644 --- a/src/PackageReferenceVersionToAttributeExtension/Logging/CustomLoggerProvider.cs +++ b/src/PackageReferenceVersionToAttributeExtension/Logging/CustomLoggerProvider.cs @@ -5,6 +5,7 @@ namespace PackageReferenceVersionToAttributeExtension.Logging { using System; + using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using PackageReferenceVersionToAttributeExtension.Services; @@ -13,9 +14,20 @@ namespace PackageReferenceVersionToAttributeExtension.Logging /// internal sealed class CustomLoggerProvider : ILoggerProvider, IDisposable { + private readonly IServiceProvider serviceProvider; + + /// + /// Initializes a new instance of the class. + /// + /// The service provider. + public CustomLoggerProvider(IServiceProvider serviceProvider) + { + this.serviceProvider = serviceProvider; + } + /// public ILogger CreateLogger(string categoryName) - => new OutputWindowLogger(); + => this.serviceProvider.GetRequiredService(); /// public void Dispose() diff --git a/src/PackageReferenceVersionToAttributeExtension/Logging/OutputWindowLogger.cs b/src/PackageReferenceVersionToAttributeExtension/Logging/OutputWindowLogger.cs index 66b5a78..854f977 100644 --- a/src/PackageReferenceVersionToAttributeExtension/Logging/OutputWindowLogger.cs +++ b/src/PackageReferenceVersionToAttributeExtension/Logging/OutputWindowLogger.cs @@ -35,6 +35,10 @@ public void Log( if (formatter != null) { var message = formatter(state, exception); + if (exception != null) + { + message += " " + exception.ToString(); + } try { diff --git a/src/PackageReferenceVersionToAttributeExtension/Package.cs b/src/PackageReferenceVersionToAttributeExtension/Package.cs index 69fce77..728f65d 100644 --- a/src/PackageReferenceVersionToAttributeExtension/Package.cs +++ b/src/PackageReferenceVersionToAttributeExtension/Package.cs @@ -65,6 +65,7 @@ protected override void InitializeServices(IServiceCollection services) .AddSingleton() .AddSingleton() .AddSingleton() + .AddSingleton() .AddLogging(configure => { configure.ClearProviders(); diff --git a/src/PackageReferenceVersionToAttributeExtension/Services/ProjectService.cs b/src/PackageReferenceVersionToAttributeExtension/Services/ProjectService.cs index fdc6a39..352f628 100644 --- a/src/PackageReferenceVersionToAttributeExtension/Services/ProjectService.cs +++ b/src/PackageReferenceVersionToAttributeExtension/Services/ProjectService.cs @@ -4,6 +4,7 @@ namespace PackageReferenceVersionToAttributeExtension.Services { + using System; using System.IO; using System.Linq; using System.Threading.Tasks; @@ -42,7 +43,18 @@ public async Task CheckOutFileAsync(string filePath) && (!this.dte.Solution.Projects.Cast().Any(x => { ThreadHelper.ThrowIfNotOnUIThread(); - return x.FileName == filePath; + + try + { + return x.FileName == filePath; + } + catch (NotImplementedException ex) + { + // ex. an unloaded project has type DteGenericProject + // ex. Exception thrown: 'System.NotImplementedException' in Microsoft.VisualStudio.CommonIDE.dll + this.logger.LogWarning(ex, $"Failed to get file name for project '{x.Name}'."); + return false; + } })))) { return;