8000 Set interceptors property for validations source generator by captainsafia · Pull Request #48891 · dotnet/sdk · GitHub
[go: up one dir, main page]

Skip to content

Set interceptors property for validations source generator #48891

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ Copyright (c) .NET Foundation. All rights reserved.
<InterceptorsPreviewNamespaces Condition="'$(EnableRequestDelegateGenerator)' == 'true'">$(InterceptorsPreviewNamespaces);Microsoft.AspNetCore.Http.Generated</InterceptorsPreviewNamespaces>
<!-- Set the namespaces emitted by the ConfigurationBindingGenerator for interception when applicable. -->
<InterceptorsPreviewNamespaces Condition="'$(EnableConfigurationBindingGenerator)' == 'true'">$(InterceptorsPreviewNamespaces);Microsoft.Extensions.Configuration.Binder.SourceGeneration</InterceptorsPreviewNamespaces>
<!-- Set the namespaces emitted by the ValidationsGenerator for interception when applicable (.NET 10 and above). -->
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could've sworn we ran into issues with the intrinsic functions that motivated us to use the default comparers but I can't track down the issue.

Actually, I tracked it down. The issue was with the IsTargetFrameworkCompatible function not the version number ones.

<InterceptorsPreviewNamespaces Condition="'$(_TargetFrameworkVersionWithoutV)' != '' and $([MSBuild]::VersionGreaterThanOrEquals('$(_TargetFrameworkVersionWithoutV)', '10.0'))">$(InterceptorsPreviewNamespaces);Microsoft.AspNetCore.Http.Validation.Generated</InterceptorsPreviewNamespaces>
</PropertyGroup>

<!--
Expand Down
18 changes: 18 additions & 0 deletions test/Microsoft.NET.Build.Tests/GivenThatWeWantToUseAnalyzers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,21 @@ public void It_enables_requestdelegategenerator_and_configbindinggenerator_for_P
VerifyInterceptorsFeatureProperties(asset, expectEnabled: true, "Microsoft.AspNetCore.Http.Generated", "Microsoft.Extensions.Configuration.Binder.SourceGeneration");
}

[Theory]
[InlineData("net10.0", true)]
[InlineData("net9.0", false)]
[InlineData("net8.0", false)]
public void It_enables_validationsgenerator_correctly_for_TargetFramework(string targetFramework, bool expectEnabled)
{
var asset = _testAssetsManager
.CopyTestAsset("WebApp")
.WithSource()
.WithTargetFramework(targetFramework);

VerifyValidationsGeneratorIsUsed(asset, expectEnabled);
VerifyInterceptorsFeatureProperties(asset, expectEnabled, "Microsoft.AspNetCore.Http.Validation.Generated");
}

[Fact]
public void It_enables_requestdelegategenerator_and_configbindinggenerator_for_PublishTrimmed()
{
Expand Down Expand Up @@ -115,6 +130,9 @@ 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 VerifyValidationsGeneratorIsUsed(TestAsset asset, bool? expectEnabled)
=> VerifyGeneratorIsUsed(asset, expectEnabled, "Microsoft.AspNetCore.Http.ValidationsGenerator.dll");

private void VerifyInterceptorsFeatureProperties(TestAsset asset, bool? expectEnabled, params string[] expectedNamespaces)
{
var command = new GetValuesCommand(
Expand Down
Loading
0