From 724178680f5cf46569a02c115d49e78d20c1c731 Mon Sep 17 00:00:00 2001 From: Ryan Nowak Date: Tue, 1 Jan 2019 16:02:33 -0800 Subject: [PATCH] Provide a public entry point for Roslyn features We need to be able to wire up these features from outside of the Razor repo. For layering reasons this can't be done in the main Razor assembly, so it can't be done by default. \n\nCommit migrated from https://github.com/dotnet/aspnetcore-tooling/commit/386e2b37970a8d8430a2ca75430ffb4b9524334e --- .../src/DiscoverCommand.cs | 6 +--- .../src/CompilerFeatures.cs | 36 +++++++++++++++++++ .../RazorIntegrationTestBase.cs | 7 +--- 3 files changed, 38 insertions(+), 11 deletions(-) create mode 100644 src/Razor/Microsoft.CodeAnalysis.Razor/src/CompilerFeatures.cs 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); }); }