Skip to content

Commit 6e5ee83

Browse files
authored
Set interceptors property for validations source generator (#48891)
1 parent 4a7b8ec commit 6e5ee83

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ Copyright (c) .NET Foundation. All rights reserved.
6868
<InterceptorsPreviewNamespaces Condition="'$(EnableRequestDelegateGenerator)' == 'true'">$(InterceptorsPreviewNamespaces);Microsoft.AspNetCore.Http.Generated</InterceptorsPreviewNamespaces>
6969
<!-- Set the namespaces emitted by the ConfigurationBindingGenerator for interception when applicable. -->
7070
<InterceptorsPreviewNamespaces Condition="'$(EnableConfigurationBindingGenerator)' == 'true'">$(InterceptorsPreviewNamespaces);Microsoft.Extensions.Configuration.Binder.SourceGeneration</InterceptorsPreviewNamespaces>
71+
<!-- Set the namespaces emitted by the ValidationsGenerator for interception when applicable (.NET 10 and above). -->
72+
<InterceptorsPreviewNamespaces Condition="'$(_TargetFrameworkVersionWithoutV)' != '' and $([MSBuild]::VersionGreaterThanOrEquals('$(_TargetFrameworkVersionWithoutV)', '10.0'))">$(InterceptorsPreviewNamespaces);Microsoft.AspNetCore.Http.Validation.Generated</InterceptorsPreviewNamespaces>
7173
</PropertyGroup>
7274

7375
<!--

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,21 @@ public void It_enables_requestdelegategenerator_and_configbindinggenerator_for_P
7373
VerifyInterceptorsFeatureProperties(asset, expectEnabled: true, "Microsoft.AspNetCore.Http.Generated", "Microsoft.Extensions.Configuration.Binder.SourceGeneration");
7474
}
7575

76+
[Theory]
77+
[InlineData("net10.0", true)]
78+
[InlineData("net9.0", false)]
79+
[InlineData("net8.0", false)]
80+
public void It_enables_validationsgenerator_correctly_for_TargetFramework(string targetFramework, bool expectEnabled)
81+
{
82+
var asset = _testAssetsManager
83+
.CopyTestAsset("WebApp")
84+
.WithSource()
85+
.WithTargetFramework(targetFramework);
86+
87+
VerifyValidationsGeneratorIsUsed(asset, expectEnabled);
88+
VerifyInterceptorsFeatureProperties(asset, expectEnabled, "Microsoft.AspNetCore.Http.Validation.Generated");
89+
}
90+
7691
[Fact]
7792
public void It_enables_requestdelegategenerator_and_configbindinggenerator_for_PublishTrimmed()
7893
{
@@ -115,6 +130,9 @@ private void VerifyRequestDelegateGeneratorIsUsed(TestAsset asset, bool? expectE
115130
private void VerifyConfigBindingGeneratorIsUsed(TestAsset asset, bool? expectEnabled)
116131
=> VerifyGeneratorIsUsed(asset, expectEnabled, "Microsoft.Extensions.Configuration.Binder.SourceGeneration.dll");
117132

133+
private void VerifyValidationsGeneratorIsUsed(TestAsset asset, bool? expectEnabled)
134+
=> VerifyGeneratorIsUsed(asset, expectEnabled, "Microsoft.AspNetCore.Http.ValidationsGenerator.dll");
135+
118136
private void VerifyInterceptorsFeatureProperties(TestAsset asset, bool? expectEnabled, params string[] expectedNamespaces)
119137
{
120138
var command = new GetValuesCommand(

0 commit comments

Comments
 (0)