Skip to content

Commit

Permalink
fix: Disabled HostBuilderExtensions generation if detected framework …
Browse files Browse the repository at this point in the history
…is none.
  • Loading branch information
HavenDV committed Mar 5, 2024
1 parent de7ecf1 commit 5c39e17
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -78,14 +68,24 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
private static EquatableArray<FileWithName> GetFrameworkSpecificSourceCode(
Framework framework)
{
var files = new List<FileWithName>();
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<FileWithName>();
return files.ToImmutableArray();
}

#endregion
Expand Down
2 changes: 1 addition & 1 deletion src/libs/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ $(PACKAGE_RELEASE_NOTES)
</PropertyGroup>

<PropertyGroup Label="Nuget">
<Version>1.5.0</Version>
<Version>1.5.1</Version>
<PackageReleaseNotes>$(PACKAGE_RELEASE_NOTES)</PackageReleaseNotes>
<GeneratePackageOnBuild Condition=" '$(Configuration)' == 'Release' ">true</GeneratePackageOnBuild>
<GenerateDocumentationFile>false</GenerateDocumentationFile>
Expand Down

0 comments on commit 5c39e17

Please sign in to comment.