diff --git a/src/Razor/Microsoft.AspNetCore.Razor.Tools/src/DiscoverCommand.cs b/src/Razor/Microsoft.AspNetCore.Razor.Tools/src/DiscoverCommand.cs index 65329ee46b..91ac10fea3 100644 --- a/src/Razor/Microsoft.AspNetCore.Razor.Tools/src/DiscoverCommand.cs +++ b/src/Razor/Microsoft.AspNetCore.Razor.Tools/src/DiscoverCommand.cs @@ -141,12 +141,8 @@ namespace Microsoft.AspNetCore.Razor.Tools b.Features.Add(new DefaultMetadataReferenceFeature() { References = metadataReferences }); b.Features.Add(new CompilationTagHelperFeature()); b.Features.Add(new DefaultTagHelperDescriptorProvider()); - b.Features.Add(new ComponentTagHelperDescriptorProvider()); - b.Features.Add(new BindTagHelperDescriptorProvider()); - b.Features.Add(new EventHandlerTagHelperDescriptorProvider()); - b.Features.Add(new RefTagHelperDescriptorProvider()); - b.Features.Add(new DefaultTypeNameFeature()); + CompilerFeatures.Register(b); }); var feature = engine.Engine.Features.OfType().Single(); diff --git a/src/Razor/Microsoft.CodeAnalysis.Razor/src/CompilerFeatures.cs b/src/Razor/Microsoft.CodeAnalysis.Razor/src/CompilerFeatures.cs new file mode 100644 index 0000000000..b42e6b5cc8 --- /dev/null +++ b/src/Razor/Microsoft.CodeAnalysis.Razor/src/CompilerFeatures.cs @@ -0,0 +1,36 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System; +using Microsoft.AspNetCore.Razor.Language; + +namespace Microsoft.CodeAnalysis.Razor +{ + /// + /// Provides access to built-in Razor features that require a reference to Microsoft.CodeAnalysis.CSharp. + /// + public static class CompilerFeatures + { + /// + /// Registers built-in Razor features that require a reference to Microsoft.CodeAnalysis.CSharp. + /// + /// The . + public static void Register(RazorProjectEngineBuilder builder) + { + if (builder == null) + { + throw new ArgumentNullException(nameof(builder)); + } + + if (builder.Configuration.LanguageVersion.CompareTo(RazorLanguageVersion.Version_3_0) >= 0) + { + builder.Features.Add(new BindTagHelperDescriptorProvider()); + builder.Features.Add(new ComponentTagHelperDescriptorProvider()); + builder.Features.Add(new EventHandlerTagHelperDescriptorProvider()); + builder.Features.Add(new RefTagHelperDescriptorProvider()); + + builder.Features.Add(new DefaultTypeNameFeature()); + } + } + } +} diff --git a/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common/Language/IntegrationTests/RazorIntegrationTestBase.cs b/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common/Language/IntegrationTests/RazorIntegrationTestBase.cs index cdadb037d4..36166cfa79 100644 --- a/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common/Language/IntegrationTests/RazorIntegrationTestBase.cs +++ b/src/Razor/test/Microsoft.AspNetCore.Razor.Test.Common/Language/IntegrationTests/RazorIntegrationTestBase.cs @@ -126,12 +126,7 @@ namespace Microsoft.AspNetCore.Razor.Language.IntegrationTests References = references, }); - b.Features.Add(new ComponentTagHelperDescriptorProvider()); - b.Features.Add(new BindTagHelperDescriptorProvider()); - b.Features.Add(new EventHandlerTagHelperDescriptorProvider()); - b.Features.Add(new RefTagHelperDescriptorProvider()); - - b.Features.Add(new DefaultTypeNameFeature()); + CompilerFeatures.Register(b); }); }