From 7c19e606881bf8ca2ba50eb4ae5d4f941326b879 Mon Sep 17 00:00:00 2001 From: Safia Abdalla Date: Tue, 29 Aug 2023 18:04:27 -0700 Subject: [PATCH 1/2] Move to granular opt-in for interceptors preview --- .../GivenThatWeWantToUseAnalyzers.cs | 16 ++++++++-------- .../Microsoft.NET.Sdk.Web.ProjectSystem.targets | 10 +++++++--- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/Tests/Microsoft.NET.Build.Tests/GivenThatWeWantToUseAnalyzers.cs b/src/Tests/Microsoft.NET.Build.Tests/GivenThatWeWantToUseAnalyzers.cs index 30f806645b6b..e83fb8126800 100644 --- a/src/Tests/Microsoft.NET.Build.Tests/GivenThatWeWantToUseAnalyzers.cs +++ b/src/Tests/Microsoft.NET.Build.Tests/GivenThatWeWantToUseAnalyzers.cs @@ -28,7 +28,7 @@ public void It_resolves_requestdelegategenerator_correctly(string testAssetName, }); VerifyRequestDelegateGeneratorIsUsed(asset, isEnabled); - VerifyInterceptorsFeatureEnabled(asset, isEnabled); + VerifyInterceptorsFeatureEnabled(asset, isEnabled, "Microsoft.AspNetCore.Http.Generated"); } [Theory] @@ -50,7 +50,7 @@ public void It_resolves_configbindinggenerator_correctly(string testAssetName, b }); VerifyConfigBindingGeneratorIsUsed(asset, isEnabled); - VerifyInterceptorsFeatureEnabled(asset, isEnabled); + VerifyInterceptorsFeatureEnabled(asset, isEnabled, "Microsoft.Extensions.Configuration.Binder.SourceGeneration"); } [Fact] @@ -67,7 +67,7 @@ public void It_enables_requestdelegategenerator_and_configbindinggenerator_for_P VerifyRequestDelegateGeneratorIsUsed(asset, expectEnabled: true); VerifyConfigBindingGeneratorIsUsed(asset, expectEnabled: true); - VerifyInterceptorsFeatureEnabled(asset, expectEnabled: true); + VerifyInterceptorsFeatureEnabled(asset, expectEnabled: true, "Microsoft.AspNetCore.Http.Generated", "Microsoft.Extensions.Configuration.Binder.SourceGeneration"); } [Fact] @@ -84,7 +84,7 @@ public void It_enables_requestdelegategenerator_and_configbindinggenerator_for_P VerifyRequestDelegateGeneratorIsUsed(asset, expectEnabled: true); VerifyConfigBindingGeneratorIsUsed(asset, expectEnabled: true); - VerifyInterceptorsFeatureEnabled(asset, expectEnabled: true); + VerifyInterceptorsFeatureEnabled(asset, expectEnabled: true, "Microsoft.AspNetCore.Http.Generated", "Microsoft.Extensions.Configuration.Binder.SourceGeneration"); } private void VerifyGeneratorIsUsed(TestAsset asset, bool? expectEnabled, string generatorName) @@ -112,13 +112,13 @@ private void VerifyRequestDelegateGeneratorIsUsed(TestAsset asset, bool? expectE private void VerifyConfigBindingGeneratorIsUsed(TestAsset asset, bool? expectEnabled) => VerifyGeneratorIsUsed(asset, expectEnabled, "Microsoft.Extensions.Configuration.Binder.SourceGeneration.dll"); - private void VerifyInterceptorsFeatureEnabled(TestAsset asset, bool? expectEnabled) + private void VerifyInterceptorsFeatureEnabled(TestAsset asset, bool? expectEnabled, params string[] expectedNamespaces) { var command = new GetValuesCommand( Log, asset.Path, ToolsetInfo.CurrentTargetFramework, - "Features", + "InterceptorsPreviewNamespaces", GetValuesCommand.ValueType.Property); command @@ -126,9 +126,9 @@ private void VerifyInterceptorsFeatureEnabled(TestAsset asset, bool? expectEnabl .Execute() .Should().Pass(); - var features = command.GetValues(); + var namespaces = command.GetValues(); - Assert.Equal(expectEnabled ?? false, features.Any(feature => feature.Contains("InterceptorsPreview"))); + Assert.Equal(expectEnabled ?? false, expectedNamespaces.All(expectedNamespace => namespaces.Contains(expectedNamespace))); } [Theory] diff --git a/src/WebSdk/ProjectSystem/Targets/Microsoft.NET.Sdk.Web.ProjectSystem.targets b/src/WebSdk/ProjectSystem/Targets/Microsoft.NET.Sdk.Web.ProjectSystem.targets index dc9cffe58d30..53230142ff10 100644 --- a/src/WebSdk/ProjectSystem/Targets/Microsoft.NET.Sdk.Web.ProjectSystem.targets +++ b/src/WebSdk/ProjectSystem/Targets/Microsoft.NET.Sdk.Web.ProjectSystem.targets @@ -59,9 +59,13 @@ Copyright (c) .NET Foundation. All rights reserved. true - - - $(Features);InterceptorsPreview + + + $(InterceptorsPreviewNamespaces);Microsoft.AspNetCore.Http.Generated + + + + $(InterceptorsPreviewNamespaces);Microsoft.Extensions.Configuration.Binder.SourceGeneration - - $(InterceptorsPreviewNamespaces);Microsoft.AspNetCore.Http.Generated - - - - $(InterceptorsPreviewNamespaces);Microsoft.Extensions.Configuration.Binder.SourceGeneration + + + $(InterceptorsPreviewNamespaces);Microsoft.AspNetCore.Http.Generated + + $(InterceptorsPreviewNamespaces);Microsoft.Extensions.Configuration.Binder.SourceGeneration