Skip to content

Commit b4dd62f

Browse files
committed
Move to granular opt-in for interceptors preview
1 parent f8b678d commit b4dd62f

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

src/Tests/Microsoft.NET.Build.Tests/GivenThatWeWantToUseAnalyzers.cs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public void It_resolves_requestdelegategenerator_correctly(string testAssetName,
2828
});
2929

3030
VerifyRequestDelegateGeneratorIsUsed(asset, isEnabled);
31-
VerifyInterceptorsFeatureEnabled(asset, isEnabled);
31+
VerifyInterceptorsFeatureEnabled(asset, isEnabled, "Microsoft.AspNetCore.Http.Generated");
3232
}
3333

3434
[Fact]
@@ -45,7 +45,7 @@ public void It_enables_requestdelegategenerator_and_configbindinggenerator_for_P
4545

4646
VerifyRequestDelegateGeneratorIsUsed(asset, expectEnabled: true);
4747
VerifyConfigBindingGeneratorIsUsed(asset, expectEnabled: true);
48-
VerifyInterceptorsFeatureEnabled(asset, expectEnabled: true);
48+
VerifyInterceptorsFeatureEnabled(asset, expectEnabled: true, "Microsoft.AspNetCore.Http.Generated", "Microsoft.Extensions.Configuration.Binder.SourceGeneration");
4949
}
5050

5151
[Fact]
@@ -62,7 +62,7 @@ public void It_enables_requestdelegategenerator_and_configbindinggenerator_for_P
6262

6363
VerifyRequestDelegateGeneratorIsUsed(asset, expectEnabled: true);
6464
VerifyConfigBindingGeneratorIsUsed(asset, expectEnabled: true);
65-
VerifyInterceptorsFeatureEnabled(asset, expectEnabled: true);
65+
VerifyInterceptorsFeatureEnabled(asset, expectEnabled: true, "Microsoft.AspNetCore.Http.Generated", "Microsoft.Extensions.Configuration.Binder.SourceGeneration");
6666
}
6767

6868
private void VerifyGeneratorIsUsed(TestAsset asset, bool? expectEnabled, string generatorName)
@@ -90,23 +90,28 @@ private void VerifyRequestDelegateGeneratorIsUsed(TestAsset asset, bool? expectE
9090
private void VerifyConfigBindingGeneratorIsUsed(TestAsset asset, bool? expectEnabled)
9191
=> VerifyGeneratorIsUsed(asset, expectEnabled, "Microsoft.Extensions.Configuration.Binder.SourceGeneration.dll");
9292

93-
private void VerifyInterceptorsFeatureEnabled(TestAsset asset, bool? expectEnabled)
93+
private void VerifyInterceptorsFeatureEnabled(TestAsset asset, bool? expectEnabled, params string[] expectedNamespaces)
9494
{
9595
var command = new GetValuesCommand(
9696
Log,
9797
asset.Path,
9898
ToolsetInfo.CurrentTargetFramework,
99-
"Features",
99+
"InterceptorsPreviewNamespaces",
100100
GetValuesCommand.ValueType.Property);
101101

102102
command
103103
.WithWorkingDirectory(asset.Path)
104104
.Execute()
105105
.Should().Pass();
106106

107-
var features = command.GetValues();
107+
var namespaces = command.GetValues();
108+
Console.WriteLine(namespaces.Count());
109+
foreach (var @namespace in namespaces)
110+
{
111+
Console.WriteLine(@namespace);
112+
}
108113

109-
Assert.Equal(expectEnabled ?? false, features.Any(feature => feature.Contains("InterceptorsPreview")));
114+
Assert.Equal(expectEnabled ?? false, expectedNamespaces.All(expectedNamespace => namespaces.Contains(expectedNamespace)));
110115
}
111116

112117
[Theory]

src/WebSdk/ProjectSystem/Targets/Microsoft.NET.Sdk.Web.ProjectSystem.targets

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,13 @@ Copyright (c) .NET Foundation. All rights reserved.
5959
<EnableConfigurationBindingGenerator Condition="'$(EnableConfigurationBindingGenerator)' == ''">true</EnableConfigurationBindingGenerator>
6060
</PropertyGroup>
6161

62-
<!-- Enable the interceptors compiler feature by default for projects that use the RequestDelegateGenerator. -->
62+
<!-- Set the namespaces emitted by the RequestDelegateGenerator for interception when applicable. -->
6363
<PropertyGroup Condition="'$(EnableRequestDelegateGenerator)' == 'true'">
64-
<Features>$(Features);InterceptorsPreview</Features>
64+
<InterceptorsPreviewNamespaces>$(InterceptorsPreviewNamespaces);Microsoft.AspNetCore.Http.Generated</InterceptorsPreviewNamespaces>
65+
</PropertyGroup>
66+
<!-- Set the namespaces emitted by the ConfigurationBindingGenerator for interception when applicable. -->
67+
<PropertyGroup Condition="'$(ConfigurationBindingGenerator)' == 'true'">
68+
<InterceptorsPreviewNamespaces>$(InterceptorsPreviewNamespaces);Microsoft.Extensions.Configuration.Binder.SourceGeneration</InterceptorsPreviewNamespaces>
6569
</PropertyGroup>
6670

6771
<!--

0 commit comments

Comments
 (0)