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 386e2b3797
This commit is contained in:
Ryan Nowak 2019-01-01 16:02:33 -08:00
parent f973693438
commit 724178680f
3 changed files with 38 additions and 11 deletions

View File

@ -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<ITagHelperFeature>().Single();

View File

@ -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
{
/// <summary>
/// Provides access to built-in Razor features that require a reference to <c>Microsoft.CodeAnalysis.CSharp</c>.
/// </summary>
public static class CompilerFeatures
{
/// <summary>
/// Registers built-in Razor features that require a reference to <c>Microsoft.CodeAnalysis.CSharp</c>.
/// </summary>
/// <param name="builder">The <see cref="RazorProjectEngineBuilder"/>.</param>
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());
}
}
}
}

View File

@ -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);
});
}