From 5c39e17ca1e86c05512f206022ae2ba08b12e391 Mon Sep 17 00:00:00 2001 From: HavenDV Date: Tue, 5 Mar 2024 04:43:01 +0400 Subject: [PATCH] fix: Disabled HostBuilderExtensions generation if detected framework is none. --- .../DependencyInjectionGenerator.cs | 24 +++++++++---------- src/libs/Directory.Build.props | 2 +- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/analyzers/Mvvm.Navigation.Generators/Generators/DependencyInjectionGenerator.cs b/src/analyzers/Mvvm.Navigation.Generators/Generators/DependencyInjectionGenerator.cs index 11b245b..b5b297a 100644 --- a/src/analyzers/Mvvm.Navigation.Generators/Generators/DependencyInjectionGenerator.cs +++ b/src/analyzers/Mvvm.Navigation.Generators/Generators/DependencyInjectionGenerator.cs @@ -17,16 +17,6 @@ public class DependencyInjectionGenerator : IIncrementalGenerator public void Initialize(IncrementalGeneratorInitializationContext context) { - context.RegisterPostInitializationOutput(static context => - { - context.AddSource( - hintName: "ServiceCollectionExtensions.d.g.cs", - source: Sources.GenerateServiceCollectionExtensionsDeclaration()); - context.AddSource( - hintName: "HostBuilderExtensions.g.cs", - source: Sources.GenerateHostBuilderExtensions()); - }); - var framework = context.TryDetectFramework(); context.SyntaxProvider @@ -78,14 +68,24 @@ private static EquatableArray GetSourceCode( private static EquatableArray GetFrameworkSpecificSourceCode( Framework framework) { + var files = new List(); + if (framework is not Framework.None) + { + files.Add(new FileWithName( + Name: "ServiceCollectionExtensions.d.g.cs", + Text: Sources.GenerateServiceCollectionExtensionsDeclaration())); + files.Add(new FileWithName( + Name: "HostBuilderExtensions.g.cs", + Text: Sources.GenerateHostBuilderExtensions())); + } if (framework is Framework.Maui) { - return ImmutableArray.Create(new FileWithName( + files.Add(new FileWithName( Name: "MauiAppBuilderExtensions.g.cs", Text: Sources.GenerateMauiAppBuilderExtensions())); } - return ImmutableArray.Create(); + return files.ToImmutableArray(); } #endregion diff --git a/src/libs/Directory.Build.props b/src/libs/Directory.Build.props index 61d058f..04e7fa5 100755 --- a/src/libs/Directory.Build.props +++ b/src/libs/Directory.Build.props @@ -23,7 +23,7 @@ $(PACKAGE_RELEASE_NOTES) - 1.5.0 + 1.5.1 $(PACKAGE_RELEASE_NOTES) true false