Skip to content

Commit 00e5eb8

Browse files
committed
Don't generate any of the registrations during design-time
This would otherwise slow down IDE/editor usage unnecessarily.
1 parent f7cb3d8 commit 00e5eb8

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

src/DependencyInjection/Devlooped.Extensions.DependencyInjection.targets

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
<ItemGroup>
1515
<CompilerVisibleProperty Include="AddServiceAttribute" />
1616
<CompilerVisibleProperty Include="AddServicesExtension" />
17+
<!-- To quickly exit if true -->
18+
<CompilerVisibleProperty Include="DesignTimeBuild" />
1719
</ItemGroup>
1820

1921
<ItemGroup Condition="'$(IsEditor)' != 'true'">

src/DependencyInjection/IncrementalGenerator.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,11 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
8686
{
8787
(var compilation, var options) = x;
8888

89-
// We won't add any registrations in this case.
90-
if (!options.GlobalOptions.TryGetValue("build_property.AddServicesExtension", out var value) ||
89+
// We won't add any registrations in these cases.
90+
if (options.IsDesignTimeBuild() ||
91+
!options.GlobalOptions.TryGetValue("build_property.AddServicesExtension", out var value) ||
9192
!bool.TryParse(value, out var addServices) || !addServices)
92-
return Enumerable.Empty<INamedTypeSymbol>();
93+
return [];
9394

9495
var visitor = new TypesVisitor(s => compilation.IsSymbolAccessible(s), c);
9596
compilation.GlobalNamespace.Accept(visitor);

0 commit comments

Comments
 (0)