From 7a41c1fdddeaa2134ee4e40c25ebecce97aaaef1 Mon Sep 17 00:00:00 2001 From: BArthur1972 Date: Wed, 22 Jun 2022 15:46:50 -0700 Subject: [PATCH 1/8] Implement analyzer to prefer builder.Services over ConfigureServices method --- .../src/Analyzers/DiagnosticDescriptors.cs | 9 + .../WebApplicationBuilderAnalyzer.cs | 40 ++ .../WebApplicationBuilder/WellKnownTypes.cs | 8 + .../DisallowConfigureServicesTest.cs | 412 ++++++++++++++++++ 4 files changed, 469 insertions(+) create mode 100644 src/Framework/AspNetCoreAnalyzers/test/WebApplicationBuilder/DisallowConfigureServicesTest.cs diff --git a/src/Framework/AspNetCoreAnalyzers/src/Analyzers/DiagnosticDescriptors.cs b/src/Framework/AspNetCoreAnalyzers/src/Analyzers/DiagnosticDescriptors.cs index c01db137deaa..22ac58fb04f8 100644 --- a/src/Framework/AspNetCoreAnalyzers/src/Analyzers/DiagnosticDescriptors.cs +++ b/src/Framework/AspNetCoreAnalyzers/src/Analyzers/DiagnosticDescriptors.cs @@ -79,4 +79,13 @@ internal static class DiagnosticDescriptors DiagnosticSeverity.Error, isEnabledByDefault: true, helpLinkUri: "https://aka.ms/aspnet/analyzers"); + + internal static readonly DiagnosticDescriptor DoNotUseHostConfigureServices = new( + "ASP0012", + "Do not use ConfigureServices with WebApplicationBuilder.Host or WebApplicationBuilder.WebHost", + "Favor using builder.Services", + "Usage", + DiagnosticSeverity.Warning, + isEnabledByDefault: true, + helpLinkUri: "https://aka.ms/aspnet/analyzers"); } diff --git a/src/Framework/AspNetCoreAnalyzers/src/Analyzers/WebApplicationBuilder/WebApplicationBuilderAnalyzer.cs b/src/Framework/AspNetCoreAnalyzers/src/Analyzers/WebApplicationBuilder/WebApplicationBuilderAnalyzer.cs index 01cfdc829a71..851ac2372b84 100644 --- a/src/Framework/AspNetCoreAnalyzers/src/Analyzers/WebApplicationBuilder/WebApplicationBuilderAnalyzer.cs +++ b/src/Framework/AspNetCoreAnalyzers/src/Analyzers/WebApplicationBuilder/WebApplicationBuilderAnalyzer.cs @@ -21,6 +21,7 @@ public class WebApplicationBuilderAnalyzer : DiagnosticAnalyzer DiagnosticDescriptors.DoNotUseConfigureWebHostWithConfigureHostBuilder, DiagnosticDescriptors.DoNotUseConfigureWithConfigureWebHostBuilder, DiagnosticDescriptors.DoNotUseUseStartupWithConfigureWebHostBuilder, + DiagnosticDescriptors.DoNotUseHostConfigureServices }); public override void Initialize(AnalysisContext context) @@ -44,6 +45,11 @@ public override void Initialize(AnalysisContext context) wellKnownTypes.HostingAbstractionsWebHostBuilderExtensions, wellKnownTypes.WebHostBuilderExtensions, }; + INamedTypeSymbol[] configureServicesTypes = + { + wellKnownTypes.HostingHostBuilderExtensions, + wellKnownTypes.ConfigureWebHostBuilder + }; compilationStartAnalysisContext.RegisterOperationAction(operationAnalysisContext => { @@ -98,6 +104,40 @@ public override void Initialize(AnalysisContext context) invocation)); } + // var builder = WebApplication.CreateBuilder(args); + // builder.Host.ConfigureServices(x => {}); + if (IsDisallowedMethod( + operationAnalysisContext, + invocation, + targetMethod, + wellKnownTypes.ConfigureHostBuilder, + "ConfigureServices", + configureServicesTypes + )) + { + operationAnalysisContext.ReportDiagnostic( + CreateDiagnostic( + DiagnosticDescriptors.DoNotUseHostConfigureServices, + invocation)); + } + + // var builder = WebApplication.CreateBuilder(args); + // builder.WebHost.ConfigureServices(x => {}); + if (IsDisallowedMethod( + operationAnalysisContext, + invocation, + targetMethod, + wellKnownTypes.ConfigureWebHostBuilder, + "ConfigureServices", + configureServicesTypes + )) + { + operationAnalysisContext.ReportDiagnostic( + CreateDiagnostic( + DiagnosticDescriptors.DoNotUseHostConfigureServices, + invocation)); + } + static Diagnostic CreateDiagnostic(DiagnosticDescriptor descriptor, IInvocationOperation operation) { // Take the location for the whole invocation operation as a starting point. diff --git a/src/Framework/AspNetCoreAnalyzers/src/Analyzers/WebApplicationBuilder/WellKnownTypes.cs b/src/Framework/AspNetCoreAnalyzers/src/Analyzers/WebApplicationBuilder/WellKnownTypes.cs index d4c43aa2a843..0e2f1102d4d1 100644 --- a/src/Framework/AspNetCoreAnalyzers/src/Analyzers/WebApplicationBuilder/WellKnownTypes.cs +++ b/src/Framework/AspNetCoreAnalyzers/src/Analyzers/WebApplicationBuilder/WellKnownTypes.cs @@ -42,6 +42,12 @@ public static bool TryCreate(Compilation compilation, [NotNullWhen(true)] out We return false; } + const string HostingHostBuilderExtensions = "Microsoft.Extensions.Hosting.HostingHostBuilderExtensions"; + if (compilation.GetTypeByMetadataName(HostingHostBuilderExtensions) is not { } hostingHostBuilderExtensions) + { + return false; + } + wellKnownTypes = new WellKnownTypes { ConfigureHostBuilder = configureHostBuilder, @@ -49,6 +55,7 @@ public static bool TryCreate(Compilation compilation, [NotNullWhen(true)] out We GenericHostWebHostBuilderExtensions = genericHostWebHostBuilderExtensions, HostingAbstractionsWebHostBuilderExtensions = hostingAbstractionsWebHostBuilderExtensions, WebHostBuilderExtensions = webHostBuilderExtensions, + HostingHostBuilderExtensions = hostingHostBuilderExtensions }; return true; @@ -59,4 +66,5 @@ public static bool TryCreate(Compilation compilation, [NotNullWhen(true)] out We public INamedTypeSymbol GenericHostWebHostBuilderExtensions { get; private init; } public INamedTypeSymbol HostingAbstractionsWebHostBuilderExtensions { get; private init; } public INamedTypeSymbol WebHostBuilderExtensions { get; private init; } + public INamedTypeSymbol HostingHostBuilderExtensions { get; private init; } } diff --git a/src/Framework/AspNetCoreAnalyzers/test/WebApplicationBuilder/DisallowConfigureServicesTest.cs b/src/Framework/AspNetCoreAnalyzers/test/WebApplicationBuilder/DisallowConfigureServicesTest.cs new file mode 100644 index 000000000000..7c6a81cf5310 --- /dev/null +++ b/src/Framework/AspNetCoreAnalyzers/test/WebApplicationBuilder/DisallowConfigureServicesTest.cs @@ -0,0 +1,412 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Analyzer.Testing; + +namespace Microsoft.AspNetCore.Analyzers.WebApplicationBuilder; +public partial class DisallowConfigureServicesTest +{ + private TestDiagnosticAnalyzerRunner Runner { get; } = new(new WebApplicationBuilderAnalyzer()); + + [Fact] + public async Task DoesNotWarnWhenBuilderConfigureServicesIsNotUsed() + { + // Arrange + var source = @" +using Microsoft.Extensions.DependencyInjection; +using Microsoft.AspNetCore.Builder; +using Microsoft.Extensions.Hosting; +var builder = WebApplication.CreateBuilder(args); +builder.Services.AddAntiforgery(); +"; + + // Act + var diagnostics = await Runner.GetDiagnosticsAsync(source); + + // Assert + Assert.Empty(diagnostics); + } + + [Fact] + public async Task WarnsWhenBuilderHostConfigureServicesIsUsed() + { + // Arrange + var source = TestSource.Read(@" +using Microsoft.Extensions.DependencyInjection; +using Microsoft.AspNetCore.Builder; +using Microsoft.Extensions.Hosting; +var builder = WebApplication.CreateBuilder(args); +builder.Host./*MM*/ConfigureServices(services => +{ +services.AddAntiforgery(); +}); +"); + + // Act + var diagnostics = await Runner.GetDiagnosticsAsync(source.Source); + + // Assert + var diagnostic = Assert.Single(diagnostics); + Assert.Same(DiagnosticDescriptors.DoNotUseHostConfigureServices, diagnostic.Descriptor); + AnalyzerAssert.DiagnosticLocation(source.DefaultMarkerLocation, diagnostic.Location); + Assert.Equal("Favor using builder.Services", diagnostic.GetMessage(CultureInfo.InvariantCulture)); + } + + [Fact] + public async Task WarnsWhenBuilderWebHostConfigureServicesIsUsed() + { + // Arrange + var source = TestSource.Read(@" +using Microsoft.Extensions.DependencyInjection; +using Microsoft.AspNetCore.Builder; +using Microsoft.Extensions.Hosting; +var builder = WebApplication.CreateBuilder(args); +builder.WebHost./*MM*/ConfigureServices(services => +{ +services.AddAntiforgery(); +}); +"); + + // Act + var diagnostics = await Runner.GetDiagnosticsAsync(source.Source); + + // Assert + var diagnostic = Assert.Single(diagnostics); + Assert.Same(DiagnosticDescriptors.DoNotUseHostConfigureServices, diagnostic.Descriptor); + AnalyzerAssert.DiagnosticLocation(source.DefaultMarkerLocation, diagnostic.Location); + Assert.Equal("Favor using builder.Services", diagnostic.GetMessage(CultureInfo.InvariantCulture)); + } + + [Fact] + public async Task WarnsWhenBuilderHostConfigureServicesIsUsed_OnDifferentLine() + { + // Arrange + var source = TestSource.Read(@" +using Microsoft.Extensions.DependencyInjection; +using Microsoft.AspNetCore.Builder; +using Microsoft.Extensions.Hosting; +var builder = WebApplication.CreateBuilder(args); +builder.Host. + /*MM*/ConfigureServices(services => + { + services.AddAntiforgery(); + }); +"); + + // Act + var diagnostics = await Runner.GetDiagnosticsAsync(source.Source); + + // Assert + var diagnostic = Assert.Single(diagnostics); + Assert.Same(DiagnosticDescriptors.DoNotUseHostConfigureServices, diagnostic.Descriptor); + AnalyzerAssert.DiagnosticLocation(source.DefaultMarkerLocation, diagnostic.Location); + Assert.Equal("Favor using builder.Services", diagnostic.GetMessage(CultureInfo.InvariantCulture)); + } + + [Fact] + public async Task WarnsWhenBuilderWebHostConfigureServicesIsUsed_OnDifferentLine() + { + // Arrange + var source = TestSource.Read(@" +using Microsoft.Extensions.DependencyInjection; +using Microsoft.AspNetCore.Builder; +using Microsoft.Extensions.Hosting; +var builder = WebApplication.CreateBuilder(args); +builder.WebHost. + /*MM*/ConfigureServices(services => + { + services.AddAntiforgery(); + }); +"); + + // Act + var diagnostics = await Runner.GetDiagnosticsAsync(source.Source); + + // Assert + var diagnostic = Assert.Single(diagnostics); + Assert.Same(DiagnosticDescriptors.DoNotUseHostConfigureServices, diagnostic.Descriptor); + AnalyzerAssert.DiagnosticLocation(source.DefaultMarkerLocation, diagnostic.Location); + Assert.Equal("Favor using builder.Services", diagnostic.GetMessage(CultureInfo.InvariantCulture)); + } + + [Fact] + public async Task DoesNotWarnWhenBuilderConfigureServicesIsNotUsed_InProgramMain() + { + // Arrange + var source = @" +using Microsoft.Extensions.DependencyInjection; +using Microsoft.AspNetCore.Builder; +using Microsoft.Extensions.Hosting; +public static class Program +{ + public static void Main(string[] args) + { + var builder = WebApplication.CreateBuilder(args); + builder.Services.AddAntiforgery(); + } +} +public class Startup { } +"; + + // Act + var diagnostics = await Runner.GetDiagnosticsAsync(source); + + // Assert + Assert.Empty(diagnostics); + } + + [Fact] + public async Task WarnsWhenBuilderHostConfigureServicesIsUsedOnProperty_In_Program_Main() + { + // Arrange + var source = TestSource.Read(@" +using Microsoft.Extensions.DependencyInjection; +using Microsoft.AspNetCore.Builder; +using Microsoft.Extensions.Hosting; +public static class Program +{ + public static void Main(string[] args) + { + var builder = WebApplication.CreateBuilder(args); + builder.Host./*MM*/ConfigureServices(services => + { + services.AddAntiforgery(); + }); + } +} +public class Startup { } +"); + + // Act + var diagnostics = await Runner.GetDiagnosticsAsync(source.Source); + + // Assert + var diagnostic = Assert.Single(diagnostics); + Assert.Same(DiagnosticDescriptors.DoNotUseHostConfigureServices, diagnostic.Descriptor); + AnalyzerAssert.DiagnosticLocation(source.DefaultMarkerLocation, diagnostic.Location); + Assert.Equal("Favor using builder.Services", diagnostic.GetMessage(CultureInfo.InvariantCulture)); + } + + [Fact] + public async Task WarnsWhenBuilderWebHostConfigureServicesIsUsedOnProperty_In_Program_Main() + { + // Arrange + var source = TestSource.Read(@" +using Microsoft.Extensions.DependencyInjection; +using Microsoft.AspNetCore.Builder; +using Microsoft.Extensions.Hosting; +public static class Program +{ + public static void Main(string[] args) + { + var builder = WebApplication.CreateBuilder(args); + builder.WebHost./*MM*/ConfigureServices(services => + { + services.AddAntiforgery(); + }); + } +} +public class Startup { } +"); + + // Act + var diagnostics = await Runner.GetDiagnosticsAsync(source.Source); + + // Assert + var diagnostic = Assert.Single(diagnostics); + Assert.Same(DiagnosticDescriptors.DoNotUseHostConfigureServices, diagnostic.Descriptor); + AnalyzerAssert.DiagnosticLocation(source.DefaultMarkerLocation, diagnostic.Location); + Assert.Equal("Favor using builder.Services", diagnostic.GetMessage(CultureInfo.InvariantCulture)); + } + + [Fact] + public async Task WarnsWhenBuilderHostConfigureServicesIsUsed_In_Program_Main() + { + // Arrange + var source = TestSource.Read(@" +using Microsoft.Extensions.DependencyInjection; +using Microsoft.AspNetCore.Builder; +using Microsoft.Extensions.Hosting; +public static class Program +{ + public static void Main(string[] args) + { + var builder = WebApplication.CreateBuilder(args); + var host = builder.Host; + host./*MM*/ConfigureServices(services => + { + services.AddAntiforgery(); + }); + } +} +public class Startup { } +"); + + // Act + var diagnostics = await Runner.GetDiagnosticsAsync(source.Source); + + // Assert + var diagnostic = Assert.Single(diagnostics); + Assert.Same(DiagnosticDescriptors.DoNotUseHostConfigureServices, diagnostic.Descriptor); + AnalyzerAssert.DiagnosticLocation(source.DefaultMarkerLocation, diagnostic.Location); + Assert.Equal("Favor using builder.Services", diagnostic.GetMessage(CultureInfo.InvariantCulture)); + } + + [Fact] + public async Task WarnsWhenBuilderWebHostConfigureServicesIsUsed_In_Program_Main() + { + // Arrange + var source = TestSource.Read(@" +using Microsoft.Extensions.DependencyInjection; +using Microsoft.AspNetCore.Builder; +using Microsoft.Extensions.Hosting; +public static class Program +{ + public static void Main(string[] args) + { + var builder = WebApplication.CreateBuilder(args); + var webHost = builder.WebHost; + webHost./*MM*/ConfigureServices(services => + { + services.AddAntiforgery(); + }); + } +} +public class Startup { } +"); + + // Act + var diagnostics = await Runner.GetDiagnosticsAsync(source.Source); + + // Assert + var diagnostic = Assert.Single(diagnostics); + Assert.Same(DiagnosticDescriptors.DoNotUseHostConfigureServices, diagnostic.Descriptor); + AnalyzerAssert.DiagnosticLocation(source.DefaultMarkerLocation, diagnostic.Location); + Assert.Equal("Favor using builder.Services", diagnostic.GetMessage(CultureInfo.InvariantCulture)); + } + + [Fact] + public async Task WarnsWhenBuilderHostConfigureServicesIsUsed_Inside_Another_Method() + { + // Arrange + var source = TestSource.Read(@" +using Microsoft.Extensions.DependencyInjection; +using Microsoft.AspNetCore.Builder; +using Microsoft.Extensions.Hosting; +public static class Program +{ + public static void Main(string[] args) + { + var builder = WebApplication.CreateBuilder(args); + ConfigureHost(builder.Host); + } + + private static void ConfigureHost(ConfigureHostBuilder hostBuilder) + { + hostBuilder + ./*MM*/ConfigureServices(services => + { + services.AddAntiforgery(); + }); + } +} +public class Startup { } +"); + + // Act + var diagnostics = await Runner.GetDiagnosticsAsync(source.Source); + + // Assert + var diagnostic = Assert.Single(diagnostics); + Assert.Same(DiagnosticDescriptors.DoNotUseHostConfigureServices, diagnostic.Descriptor); + AnalyzerAssert.DiagnosticLocation(source.DefaultMarkerLocation, diagnostic.Location); + Assert.Equal("Favor using builder.Services", diagnostic.GetMessage(CultureInfo.InvariantCulture)); + } + + [Fact] + public async Task WarnsTwiceWhenBuilderHostConfigureServicesIsUsed_Twice() + { + // Arrange + var source = TestSource.Read(@" +using Microsoft.Extensions.DependencyInjection; +using Microsoft.AspNetCore.Builder; +using Microsoft.Extensions.Hosting; +var builder = WebApplication.CreateBuilder(args); +builder.Host./*MM1*/ConfigureServices(services => +{ + services.AddAntiforgery(); +}); +builder.Host./*MM2*/ConfigureServices(services => +{ + services.AddAntiforgery(); +}); +"); + + // Act + var diagnostics = await Runner.GetDiagnosticsAsync(source.Source); + + // Asserts + Assert.Equal(2, diagnostics.Length); + + // First diagnostic + var firstDiagnostic = diagnostics[0]; + + Assert.Same(DiagnosticDescriptors.DoNotUseHostConfigureServices, firstDiagnostic.Descriptor); + AnalyzerAssert.DiagnosticLocation(source.MarkerLocations["MM1"], firstDiagnostic.Location); + Assert.Equal("Favor using builder.Services", firstDiagnostic.GetMessage(CultureInfo.InvariantCulture)); + + // Second diagnostic + var secondDiagnostic = diagnostics[1]; + + Assert.Same(DiagnosticDescriptors.DoNotUseHostConfigureServices, secondDiagnostic.Descriptor); + AnalyzerAssert.DiagnosticLocation(source.MarkerLocations["MM2"], secondDiagnostic.Location); + Assert.Equal("Favor using builder.Services", secondDiagnostic.GetMessage(CultureInfo.InvariantCulture)); + } + + [Fact] + public async Task WarnsTwiceWhenBuilderWebHostConfigureServicesIsUsed_Twice() + { + // Arrange + var source = TestSource.Read(@" +using Microsoft.Extensions.DependencyInjection; +using Microsoft.AspNetCore.Builder; +using Microsoft.Extensions.Hosting; +var builder = WebApplication.CreateBuilder(args); +builder.WebHost./*MM1*/ConfigureServices(services => +{ + services.AddAntiforgery(); +}); +builder.WebHost./*MM2*/ConfigureServices(services => +{ + services.AddAntiforgery(); +}); +"); + + // Act + var diagnostics = await Runner.GetDiagnosticsAsync(source.Source); + + // Asserts + Assert.Equal(2, diagnostics.Length); + + // First diagnostic + var firstDiagnostic = diagnostics[0]; + + Assert.Same(DiagnosticDescriptors.DoNotUseHostConfigureServices, firstDiagnostic.Descriptor); + AnalyzerAssert.DiagnosticLocation(source.MarkerLocations["MM1"], firstDiagnostic.Location); + Assert.Equal("Favor using builder.Services", firstDiagnostic.GetMessage(CultureInfo.InvariantCulture)); + + // Second diagnostic + var secondDiagnostic = diagnostics[1]; + + Assert.Same(DiagnosticDescriptors.DoNotUseHostConfigureServices, secondDiagnostic.Descriptor); + AnalyzerAssert.DiagnosticLocation(source.MarkerLocations["MM2"], secondDiagnostic.Location); + Assert.Equal("Favor using builder.Services", secondDiagnostic.GetMessage(CultureInfo.InvariantCulture)); + } + +} From 77851ae48304201704b4f6c32a9cdfd7a9e946f9 Mon Sep 17 00:00:00 2001 From: BArthur1972 <82739341+BArthur1972@users.noreply.github.com> Date: Thu, 23 Jun 2022 09:27:58 -0700 Subject: [PATCH 2/8] Update src/Framework/AspNetCoreAnalyzers/src/Analyzers/DiagnosticDescriptors.cs Co-authored-by: Safia Abdalla --- .../AspNetCoreAnalyzers/src/Analyzers/DiagnosticDescriptors.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Framework/AspNetCoreAnalyzers/src/Analyzers/DiagnosticDescriptors.cs b/src/Framework/AspNetCoreAnalyzers/src/Analyzers/DiagnosticDescriptors.cs index 22ac58fb04f8..af1e83f40998 100644 --- a/src/Framework/AspNetCoreAnalyzers/src/Analyzers/DiagnosticDescriptors.cs +++ b/src/Framework/AspNetCoreAnalyzers/src/Analyzers/DiagnosticDescriptors.cs @@ -83,7 +83,7 @@ internal static class DiagnosticDescriptors internal static readonly DiagnosticDescriptor DoNotUseHostConfigureServices = new( "ASP0012", "Do not use ConfigureServices with WebApplicationBuilder.Host or WebApplicationBuilder.WebHost", - "Favor using builder.Services", + "Favor using builder.Services over ConfigureServices", "Usage", DiagnosticSeverity.Warning, isEnabledByDefault: true, From 42b6f5eb305abdb06d910a77e41284c356c187d0 Mon Sep 17 00:00:00 2001 From: BArthur1972 <82739341+BArthur1972@users.noreply.github.com> Date: Thu, 23 Jun 2022 10:29:13 -0700 Subject: [PATCH 3/8] Update src/Framework/AspNetCoreAnalyzers/src/Analyzers/DiagnosticDescriptors.cs Co-authored-by: Safia Abdalla --- .../AspNetCoreAnalyzers/src/Analyzers/DiagnosticDescriptors.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Framework/AspNetCoreAnalyzers/src/Analyzers/DiagnosticDescriptors.cs b/src/Framework/AspNetCoreAnalyzers/src/Analyzers/DiagnosticDescriptors.cs index af1e83f40998..3f4e265957f9 100644 --- a/src/Framework/AspNetCoreAnalyzers/src/Analyzers/DiagnosticDescriptors.cs +++ b/src/Framework/AspNetCoreAnalyzers/src/Analyzers/DiagnosticDescriptors.cs @@ -82,7 +82,7 @@ internal static class DiagnosticDescriptors internal static readonly DiagnosticDescriptor DoNotUseHostConfigureServices = new( "ASP0012", - "Do not use ConfigureServices with WebApplicationBuilder.Host or WebApplicationBuilder.WebHost", + "Use Host.Services or WebHost.Services over ConfigureServices", "Favor using builder.Services over ConfigureServices", "Usage", DiagnosticSeverity.Warning, From fcf606f7ff875bf2f06d6268515c64b13ea7139f Mon Sep 17 00:00:00 2001 From: BArthur1972 Date: Thu, 23 Jun 2022 10:40:24 -0700 Subject: [PATCH 4/8] Rephrase the warnings in the diagnostic descriptor and the tests --- .../src/Analyzers/DiagnosticDescriptors.cs | 4 +-- .../DisallowConfigureServicesTest.cs | 26 +++++++++---------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/Framework/AspNetCoreAnalyzers/src/Analyzers/DiagnosticDescriptors.cs b/src/Framework/AspNetCoreAnalyzers/src/Analyzers/DiagnosticDescriptors.cs index 22ac58fb04f8..3f4e265957f9 100644 --- a/src/Framework/AspNetCoreAnalyzers/src/Analyzers/DiagnosticDescriptors.cs +++ b/src/Framework/AspNetCoreAnalyzers/src/Analyzers/DiagnosticDescriptors.cs @@ -82,8 +82,8 @@ internal static class DiagnosticDescriptors internal static readonly DiagnosticDescriptor DoNotUseHostConfigureServices = new( "ASP0012", - "Do not use ConfigureServices with WebApplicationBuilder.Host or WebApplicationBuilder.WebHost", - "Favor using builder.Services", + "Use Host.Services or WebHost.Services over ConfigureServices", + "Favor using builder.Services over ConfigureServices", "Usage", DiagnosticSeverity.Warning, isEnabledByDefault: true, diff --git a/src/Framework/AspNetCoreAnalyzers/test/WebApplicationBuilder/DisallowConfigureServicesTest.cs b/src/Framework/AspNetCoreAnalyzers/test/WebApplicationBuilder/DisallowConfigureServicesTest.cs index 7c6a81cf5310..afe351844c0a 100644 --- a/src/Framework/AspNetCoreAnalyzers/test/WebApplicationBuilder/DisallowConfigureServicesTest.cs +++ b/src/Framework/AspNetCoreAnalyzers/test/WebApplicationBuilder/DisallowConfigureServicesTest.cs @@ -55,7 +55,7 @@ public async Task WarnsWhenBuilderHostConfigureServicesIsUsed() var diagnostic = Assert.Single(diagnostics); Assert.Same(DiagnosticDescriptors.DoNotUseHostConfigureServices, diagnostic.Descriptor); AnalyzerAssert.DiagnosticLocation(source.DefaultMarkerLocation, diagnostic.Location); - Assert.Equal("Favor using builder.Services", diagnostic.GetMessage(CultureInfo.InvariantCulture)); + Assert.Equal("Favor using builder.Services over ConfigureServices", diagnostic.GetMessage(CultureInfo.InvariantCulture)); } [Fact] @@ -80,7 +80,7 @@ public async Task WarnsWhenBuilderWebHostConfigureServicesIsUsed() var diagnostic = Assert.Single(diagnostics); Assert.Same(DiagnosticDescriptors.DoNotUseHostConfigureServices, diagnostic.Descriptor); AnalyzerAssert.DiagnosticLocation(source.DefaultMarkerLocation, diagnostic.Location); - Assert.Equal("Favor using builder.Services", diagnostic.GetMessage(CultureInfo.InvariantCulture)); + Assert.Equal("Favor using builder.Services over ConfigureServices", diagnostic.GetMessage(CultureInfo.InvariantCulture)); } [Fact] @@ -106,7 +106,7 @@ public async Task WarnsWhenBuilderHostConfigureServicesIsUsed_OnDifferentLine() var diagnostic = Assert.Single(diagnostics); Assert.Same(DiagnosticDescriptors.DoNotUseHostConfigureServices, diagnostic.Descriptor); AnalyzerAssert.DiagnosticLocation(source.DefaultMarkerLocation, diagnostic.Location); - Assert.Equal("Favor using builder.Services", diagnostic.GetMessage(CultureInfo.InvariantCulture)); + Assert.Equal("Favor using builder.Services over ConfigureServices", diagnostic.GetMessage(CultureInfo.InvariantCulture)); } [Fact] @@ -132,7 +132,7 @@ public async Task WarnsWhenBuilderWebHostConfigureServicesIsUsed_OnDifferentLine var diagnostic = Assert.Single(diagnostics); Assert.Same(DiagnosticDescriptors.DoNotUseHostConfigureServices, diagnostic.Descriptor); AnalyzerAssert.DiagnosticLocation(source.DefaultMarkerLocation, diagnostic.Location); - Assert.Equal("Favor using builder.Services", diagnostic.GetMessage(CultureInfo.InvariantCulture)); + Assert.Equal("Favor using builder.Services over ConfigureServices", diagnostic.GetMessage(CultureInfo.InvariantCulture)); } [Fact] @@ -190,7 +190,7 @@ public class Startup { } var diagnostic = Assert.Single(diagnostics); Assert.Same(DiagnosticDescriptors.DoNotUseHostConfigureServices, diagnostic.Descriptor); AnalyzerAssert.DiagnosticLocation(source.DefaultMarkerLocation, diagnostic.Location); - Assert.Equal("Favor using builder.Services", diagnostic.GetMessage(CultureInfo.InvariantCulture)); + Assert.Equal("Favor using builder.Services over ConfigureServices", diagnostic.GetMessage(CultureInfo.InvariantCulture)); } [Fact] @@ -222,7 +222,7 @@ public class Startup { } var diagnostic = Assert.Single(diagnostics); Assert.Same(DiagnosticDescriptors.DoNotUseHostConfigureServices, diagnostic.Descriptor); AnalyzerAssert.DiagnosticLocation(source.DefaultMarkerLocation, diagnostic.Location); - Assert.Equal("Favor using builder.Services", diagnostic.GetMessage(CultureInfo.InvariantCulture)); + Assert.Equal("Favor using builder.Services over ConfigureServices", diagnostic.GetMessage(CultureInfo.InvariantCulture)); } [Fact] @@ -255,7 +255,7 @@ public class Startup { } var diagnostic = Assert.Single(diagnostics); Assert.Same(DiagnosticDescriptors.DoNotUseHostConfigureServices, diagnostic.Descriptor); AnalyzerAssert.DiagnosticLocation(source.DefaultMarkerLocation, diagnostic.Location); - Assert.Equal("Favor using builder.Services", diagnostic.GetMessage(CultureInfo.InvariantCulture)); + Assert.Equal("Favor using builder.Services over ConfigureServices", diagnostic.GetMessage(CultureInfo.InvariantCulture)); } [Fact] @@ -288,7 +288,7 @@ public class Startup { } var diagnostic = Assert.Single(diagnostics); Assert.Same(DiagnosticDescriptors.DoNotUseHostConfigureServices, diagnostic.Descriptor); AnalyzerAssert.DiagnosticLocation(source.DefaultMarkerLocation, diagnostic.Location); - Assert.Equal("Favor using builder.Services", diagnostic.GetMessage(CultureInfo.InvariantCulture)); + Assert.Equal("Favor using builder.Services over ConfigureServices", diagnostic.GetMessage(CultureInfo.InvariantCulture)); } [Fact] @@ -326,7 +326,7 @@ public class Startup { } var diagnostic = Assert.Single(diagnostics); Assert.Same(DiagnosticDescriptors.DoNotUseHostConfigureServices, diagnostic.Descriptor); AnalyzerAssert.DiagnosticLocation(source.DefaultMarkerLocation, diagnostic.Location); - Assert.Equal("Favor using builder.Services", diagnostic.GetMessage(CultureInfo.InvariantCulture)); + Assert.Equal("Favor using builder.Services over ConfigureServices", diagnostic.GetMessage(CultureInfo.InvariantCulture)); } [Fact] @@ -359,14 +359,14 @@ public async Task WarnsTwiceWhenBuilderHostConfigureServicesIsUsed_Twice() Assert.Same(DiagnosticDescriptors.DoNotUseHostConfigureServices, firstDiagnostic.Descriptor); AnalyzerAssert.DiagnosticLocation(source.MarkerLocations["MM1"], firstDiagnostic.Location); - Assert.Equal("Favor using builder.Services", firstDiagnostic.GetMessage(CultureInfo.InvariantCulture)); + Assert.Equal("Favor using builder.Services over ConfigureServices", firstDiagnostic.GetMessage(CultureInfo.InvariantCulture)); // Second diagnostic var secondDiagnostic = diagnostics[1]; Assert.Same(DiagnosticDescriptors.DoNotUseHostConfigureServices, secondDiagnostic.Descriptor); AnalyzerAssert.DiagnosticLocation(source.MarkerLocations["MM2"], secondDiagnostic.Location); - Assert.Equal("Favor using builder.Services", secondDiagnostic.GetMessage(CultureInfo.InvariantCulture)); + Assert.Equal("Favor using builder.Services over ConfigureServices", secondDiagnostic.GetMessage(CultureInfo.InvariantCulture)); } [Fact] @@ -399,14 +399,14 @@ public async Task WarnsTwiceWhenBuilderWebHostConfigureServicesIsUsed_Twice() Assert.Same(DiagnosticDescriptors.DoNotUseHostConfigureServices, firstDiagnostic.Descriptor); AnalyzerAssert.DiagnosticLocation(source.MarkerLocations["MM1"], firstDiagnostic.Location); - Assert.Equal("Favor using builder.Services", firstDiagnostic.GetMessage(CultureInfo.InvariantCulture)); + Assert.Equal("Favor using builder.Services over ConfigureServices", firstDiagnostic.GetMessage(CultureInfo.InvariantCulture)); // Second diagnostic var secondDiagnostic = diagnostics[1]; Assert.Same(DiagnosticDescriptors.DoNotUseHostConfigureServices, secondDiagnostic.Descriptor); AnalyzerAssert.DiagnosticLocation(source.MarkerLocations["MM2"], secondDiagnostic.Location); - Assert.Equal("Favor using builder.Services", secondDiagnostic.GetMessage(CultureInfo.InvariantCulture)); + Assert.Equal("Favor using builder.Services over ConfigureServices", secondDiagnostic.GetMessage(CultureInfo.InvariantCulture)); } } From b3c0034d5e03cfcf066ea702c0507dc4af859d5e Mon Sep 17 00:00:00 2001 From: BArthur1972 Date: Fri, 24 Jun 2022 15:30:41 -0700 Subject: [PATCH 5/8] Update the title and warning in the diagnostic descriptor --- .../src/Analyzers/DiagnosticDescriptors.cs | 4 +-- .../WebApplicationBuilderAnalyzer.cs | 2 +- .../DisallowConfigureServicesTest.cs | 26 +++++++++---------- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/Framework/AspNetCoreAnalyzers/src/Analyzers/DiagnosticDescriptors.cs b/src/Framework/AspNetCoreAnalyzers/src/Analyzers/DiagnosticDescriptors.cs index 3f4e265957f9..067f2c609271 100644 --- a/src/Framework/AspNetCoreAnalyzers/src/Analyzers/DiagnosticDescriptors.cs +++ b/src/Framework/AspNetCoreAnalyzers/src/Analyzers/DiagnosticDescriptors.cs @@ -82,8 +82,8 @@ internal static class DiagnosticDescriptors internal static readonly DiagnosticDescriptor DoNotUseHostConfigureServices = new( "ASP0012", - "Use Host.Services or WebHost.Services over ConfigureServices", - "Favor using builder.Services over ConfigureServices", + "Suggest using builder.Services over Host.ConfigureServices or WebHost.ConfigureServices", + "Suggest using builder.Services instead of {0}", "Usage", DiagnosticSeverity.Warning, isEnabledByDefault: true, diff --git a/src/Framework/AspNetCoreAnalyzers/src/Analyzers/WebApplicationBuilder/WebApplicationBuilderAnalyzer.cs b/src/Framework/AspNetCoreAnalyzers/src/Analyzers/WebApplicationBuilder/WebApplicationBuilderAnalyzer.cs index 851ac2372b84..d5a2ff077f11 100644 --- a/src/Framework/AspNetCoreAnalyzers/src/Analyzers/WebApplicationBuilder/WebApplicationBuilderAnalyzer.cs +++ b/src/Framework/AspNetCoreAnalyzers/src/Analyzers/WebApplicationBuilder/WebApplicationBuilderAnalyzer.cs @@ -187,7 +187,7 @@ static Diagnostic CreateDiagnostic(DiagnosticDescriptor descriptor, IInvocationO location = Location.Create(operation.Syntax.SyntaxTree, targetSpan); } - return Diagnostic.Create(descriptor, location); + return Diagnostic.Create(descriptor, location, methodName); } }, OperationKind.Invocation); diff --git a/src/Framework/AspNetCoreAnalyzers/test/WebApplicationBuilder/DisallowConfigureServicesTest.cs b/src/Framework/AspNetCoreAnalyzers/test/WebApplicationBuilder/DisallowConfigureServicesTest.cs index afe351844c0a..c8263a9dd89c 100644 --- a/src/Framework/AspNetCoreAnalyzers/test/WebApplicationBuilder/DisallowConfigureServicesTest.cs +++ b/src/Framework/AspNetCoreAnalyzers/test/WebApplicationBuilder/DisallowConfigureServicesTest.cs @@ -55,7 +55,7 @@ public async Task WarnsWhenBuilderHostConfigureServicesIsUsed() var diagnostic = Assert.Single(diagnostics); Assert.Same(DiagnosticDescriptors.DoNotUseHostConfigureServices, diagnostic.Descriptor); AnalyzerAssert.DiagnosticLocation(source.DefaultMarkerLocation, diagnostic.Location); - Assert.Equal("Favor using builder.Services over ConfigureServices", diagnostic.GetMessage(CultureInfo.InvariantCulture)); + Assert.Equal("Suggest using builder.Services instead of ConfigureServices", diagnostic.GetMessage(CultureInfo.InvariantCulture)); } [Fact] @@ -80,7 +80,7 @@ public async Task WarnsWhenBuilderWebHostConfigureServicesIsUsed() var diagnostic = Assert.Single(diagnostics); Assert.Same(DiagnosticDescriptors.DoNotUseHostConfigureServices, diagnostic.Descriptor); AnalyzerAssert.DiagnosticLocation(source.DefaultMarkerLocation, diagnostic.Location); - Assert.Equal("Favor using builder.Services over ConfigureServices", diagnostic.GetMessage(CultureInfo.InvariantCulture)); + Assert.Equal("Suggest using builder.Services instead of ConfigureServices", diagnostic.GetMessage(CultureInfo.InvariantCulture)); } [Fact] @@ -106,7 +106,7 @@ public async Task WarnsWhenBuilderHostConfigureServicesIsUsed_OnDifferentLine() var diagnostic = Assert.Single(diagnostics); Assert.Same(DiagnosticDescriptors.DoNotUseHostConfigureServices, diagnostic.Descriptor); AnalyzerAssert.DiagnosticLocation(source.DefaultMarkerLocation, diagnostic.Location); - Assert.Equal("Favor using builder.Services over ConfigureServices", diagnostic.GetMessage(CultureInfo.InvariantCulture)); + Assert.Equal("Suggest using builder.Services instead of ConfigureServices", diagnostic.GetMessage(CultureInfo.InvariantCulture)); } [Fact] @@ -132,7 +132,7 @@ public async Task WarnsWhenBuilderWebHostConfigureServicesIsUsed_OnDifferentLine var diagnostic = Assert.Single(diagnostics); Assert.Same(DiagnosticDescriptors.DoNotUseHostConfigureServices, diagnostic.Descriptor); AnalyzerAssert.DiagnosticLocation(source.DefaultMarkerLocation, diagnostic.Location); - Assert.Equal("Favor using builder.Services over ConfigureServices", diagnostic.GetMessage(CultureInfo.InvariantCulture)); + Assert.Equal("Suggest using builder.Services instead of ConfigureServices", diagnostic.GetMessage(CultureInfo.InvariantCulture)); } [Fact] @@ -190,7 +190,7 @@ public class Startup { } var diagnostic = Assert.Single(diagnostics); Assert.Same(DiagnosticDescriptors.DoNotUseHostConfigureServices, diagnostic.Descriptor); AnalyzerAssert.DiagnosticLocation(source.DefaultMarkerLocation, diagnostic.Location); - Assert.Equal("Favor using builder.Services over ConfigureServices", diagnostic.GetMessage(CultureInfo.InvariantCulture)); + Assert.Equal("Suggest using builder.Services instead of ConfigureServices", diagnostic.GetMessage(CultureInfo.InvariantCulture)); } [Fact] @@ -222,7 +222,7 @@ public class Startup { } var diagnostic = Assert.Single(diagnostics); Assert.Same(DiagnosticDescriptors.DoNotUseHostConfigureServices, diagnostic.Descriptor); AnalyzerAssert.DiagnosticLocation(source.DefaultMarkerLocation, diagnostic.Location); - Assert.Equal("Favor using builder.Services over ConfigureServices", diagnostic.GetMessage(CultureInfo.InvariantCulture)); + Assert.Equal("Suggest using builder.Services instead of ConfigureServices", diagnostic.GetMessage(CultureInfo.InvariantCulture)); } [Fact] @@ -255,7 +255,7 @@ public class Startup { } var diagnostic = Assert.Single(diagnostics); Assert.Same(DiagnosticDescriptors.DoNotUseHostConfigureServices, diagnostic.Descriptor); AnalyzerAssert.DiagnosticLocation(source.DefaultMarkerLocation, diagnostic.Location); - Assert.Equal("Favor using builder.Services over ConfigureServices", diagnostic.GetMessage(CultureInfo.InvariantCulture)); + Assert.Equal("Suggest using builder.Services instead of ConfigureServices", diagnostic.GetMessage(CultureInfo.InvariantCulture)); } [Fact] @@ -288,7 +288,7 @@ public class Startup { } var diagnostic = Assert.Single(diagnostics); Assert.Same(DiagnosticDescriptors.DoNotUseHostConfigureServices, diagnostic.Descriptor); AnalyzerAssert.DiagnosticLocation(source.DefaultMarkerLocation, diagnostic.Location); - Assert.Equal("Favor using builder.Services over ConfigureServices", diagnostic.GetMessage(CultureInfo.InvariantCulture)); + Assert.Equal("Suggest using builder.Services instead of ConfigureServices", diagnostic.GetMessage(CultureInfo.InvariantCulture)); } [Fact] @@ -326,7 +326,7 @@ public class Startup { } var diagnostic = Assert.Single(diagnostics); Assert.Same(DiagnosticDescriptors.DoNotUseHostConfigureServices, diagnostic.Descriptor); AnalyzerAssert.DiagnosticLocation(source.DefaultMarkerLocation, diagnostic.Location); - Assert.Equal("Favor using builder.Services over ConfigureServices", diagnostic.GetMessage(CultureInfo.InvariantCulture)); + Assert.Equal("Suggest using builder.Services instead of ConfigureServices", diagnostic.GetMessage(CultureInfo.InvariantCulture)); } [Fact] @@ -359,14 +359,14 @@ public async Task WarnsTwiceWhenBuilderHostConfigureServicesIsUsed_Twice() Assert.Same(DiagnosticDescriptors.DoNotUseHostConfigureServices, firstDiagnostic.Descriptor); AnalyzerAssert.DiagnosticLocation(source.MarkerLocations["MM1"], firstDiagnostic.Location); - Assert.Equal("Favor using builder.Services over ConfigureServices", firstDiagnostic.GetMessage(CultureInfo.InvariantCulture)); + Assert.Equal("Suggest using builder.Services instead of ConfigureServices", firstDiagnostic.GetMessage(CultureInfo.InvariantCulture)); // Second diagnostic var secondDiagnostic = diagnostics[1]; Assert.Same(DiagnosticDescriptors.DoNotUseHostConfigureServices, secondDiagnostic.Descriptor); AnalyzerAssert.DiagnosticLocation(source.MarkerLocations["MM2"], secondDiagnostic.Location); - Assert.Equal("Favor using builder.Services over ConfigureServices", secondDiagnostic.GetMessage(CultureInfo.InvariantCulture)); + Assert.Equal("Suggest using builder.Services instead of ConfigureServices", secondDiagnostic.GetMessage(CultureInfo.InvariantCulture)); } [Fact] @@ -399,14 +399,14 @@ public async Task WarnsTwiceWhenBuilderWebHostConfigureServicesIsUsed_Twice() Assert.Same(DiagnosticDescriptors.DoNotUseHostConfigureServices, firstDiagnostic.Descriptor); AnalyzerAssert.DiagnosticLocation(source.MarkerLocations["MM1"], firstDiagnostic.Location); - Assert.Equal("Favor using builder.Services over ConfigureServices", firstDiagnostic.GetMessage(CultureInfo.InvariantCulture)); + Assert.Equal("Suggest using builder.Services instead of ConfigureServices", firstDiagnostic.GetMessage(CultureInfo.InvariantCulture)); // Second diagnostic var secondDiagnostic = diagnostics[1]; Assert.Same(DiagnosticDescriptors.DoNotUseHostConfigureServices, secondDiagnostic.Descriptor); AnalyzerAssert.DiagnosticLocation(source.MarkerLocations["MM2"], secondDiagnostic.Location); - Assert.Equal("Favor using builder.Services over ConfigureServices", secondDiagnostic.GetMessage(CultureInfo.InvariantCulture)); + Assert.Equal("Suggest using builder.Services instead of ConfigureServices", secondDiagnostic.GetMessage(CultureInfo.InvariantCulture)); } } From c86cd48a7c4eb7c5c6142ccfd833e5bfb522d925 Mon Sep 17 00:00:00 2001 From: BArthur1972 <82739341+BArthur1972@users.noreply.github.com> Date: Tue, 28 Jun 2022 17:16:19 -0700 Subject: [PATCH 6/8] Resolved merge conflict in WebApplicationBuilderAnalyzer.cs --- .../WebApplicationBuilder/WebApplicationBuilderAnalyzer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Framework/AspNetCoreAnalyzers/src/Analyzers/WebApplicationBuilder/WebApplicationBuilderAnalyzer.cs b/src/Framework/AspNetCoreAnalyzers/src/Analyzers/WebApplicationBuilder/WebApplicationBuilderAnalyzer.cs index b25528ba361a..48aa13dfda8d 100644 --- a/src/Framework/AspNetCoreAnalyzers/src/Analyzers/WebApplicationBuilder/WebApplicationBuilderAnalyzer.cs +++ b/src/Framework/AspNetCoreAnalyzers/src/Analyzers/WebApplicationBuilder/WebApplicationBuilderAnalyzer.cs @@ -21,8 +21,8 @@ public class WebApplicationBuilderAnalyzer : DiagnosticAnalyzer DiagnosticDescriptors.DoNotUseConfigureWebHostWithConfigureHostBuilder, DiagnosticDescriptors.DoNotUseConfigureWithConfigureWebHostBuilder, DiagnosticDescriptors.DoNotUseUseStartupWithConfigureWebHostBuilder, + DiagnosticDescriptors.DoNotUseHostConfigureLogging, DiagnosticDescriptors.DoNotUseHostConfigureServices - DiagnosticDescriptors.DoNotUseHostConfigureLogging }); public override void Initialize(AnalysisContext context) From 37c23b5ca6b7462aab10f625bf76865e50a5ee18 Mon Sep 17 00:00:00 2001 From: BArthur1972 <82739341+BArthur1972@users.noreply.github.com> Date: Tue, 28 Jun 2022 17:33:31 -0700 Subject: [PATCH 7/8] Resolve merge conflicts --- .../WebApplicationBuilder/WebApplicationBuilderAnalyzer.cs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/Framework/AspNetCoreAnalyzers/src/Analyzers/WebApplicationBuilder/WebApplicationBuilderAnalyzer.cs b/src/Framework/AspNetCoreAnalyzers/src/Analyzers/WebApplicationBuilder/WebApplicationBuilderAnalyzer.cs index 48aa13dfda8d..abd9bfbd8a1f 100644 --- a/src/Framework/AspNetCoreAnalyzers/src/Analyzers/WebApplicationBuilder/WebApplicationBuilderAnalyzer.cs +++ b/src/Framework/AspNetCoreAnalyzers/src/Analyzers/WebApplicationBuilder/WebApplicationBuilderAnalyzer.cs @@ -145,8 +145,7 @@ public override void Initialize(AnalysisContext context) targetMethod, wellKnownTypes.ConfigureHostBuilder, "ConfigureServices", - configureServicesTypes - )) + configureServicesTypes)) { operationAnalysisContext.ReportDiagnostic( CreateDiagnostic( @@ -162,8 +161,7 @@ public override void Initialize(AnalysisContext context) targetMethod, wellKnownTypes.ConfigureWebHostBuilder, "ConfigureServices", - configureServicesTypes - )) + configureServicesTypes)) { operationAnalysisContext.ReportDiagnostic( CreateDiagnostic( From 103a4aa97ed617a1eb506eee5fce36609e621f1e Mon Sep 17 00:00:00 2001 From: BArthur1972 <82739341+BArthur1972@users.noreply.github.com> Date: Tue, 28 Jun 2022 17:43:35 -0700 Subject: [PATCH 8/8] Add configureServicesTypes to WebApplicationBuilderAnalyzer.cs --- .../WebApplicationBuilder/WebApplicationBuilderAnalyzer.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Framework/AspNetCoreAnalyzers/src/Analyzers/WebApplicationBuilder/WebApplicationBuilderAnalyzer.cs b/src/Framework/AspNetCoreAnalyzers/src/Analyzers/WebApplicationBuilder/WebApplicationBuilderAnalyzer.cs index abd9bfbd8a1f..8ead1057b28d 100644 --- a/src/Framework/AspNetCoreAnalyzers/src/Analyzers/WebApplicationBuilder/WebApplicationBuilderAnalyzer.cs +++ b/src/Framework/AspNetCoreAnalyzers/src/Analyzers/WebApplicationBuilder/WebApplicationBuilderAnalyzer.cs @@ -51,6 +51,11 @@ public override void Initialize(AnalysisContext context) wellKnownTypes.HostingHostBuilderExtensions, wellKnownTypes.WebHostBuilderExtensions }; + INamedTypeSymbol[] configureServicesTypes = + { + wellKnownTypes.HostingHostBuilderExtensions, + wellKnownTypes.ConfigureWebHostBuilder + }; compilationStartAnalysisContext.RegisterOperationAction(operationAnalysisContext => {