Add SuppressMvcRazorImports configuration option#12849
Draft
DamianEdwards wants to merge 1 commit intomainfrom
Draft
Add SuppressMvcRazorImports configuration option#12849DamianEdwards wants to merge 1 commit intomainfrom
DamianEdwards wants to merge 1 commit intomainfrom
Conversation
Add a new SuppressMvcRazorImports boolean property to RazorConfiguration that, when set to true via MSBuild property, suppresses all MVC-specific default directives from the synthetic import in MvcImportProjectFeature. When enabled, the default import retains only System @using directives. The following MVC-specific directives are suppressed: - 3 @using Microsoft.AspNetCore.Mvc.* directives - 5 @Inject directives (IHtmlHelper, IJsonHelper, etc.) - 3 @addTagHelper directives (UrlResolution, Head, Body) Explicit @Inject, @using, and @addTagHelper directives in .cshtml or _ViewImports.cshtml files continue to work regardless of this setting. Users set <SuppressMvcRazorImports>true</SuppressMvcRazorImports> in their project file. A follow-up change in dotnet/sdk is needed to add the corresponding CompilerVisibleProperty declaration. Fixes #8259 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a new
SuppressMvcRazorImportsMSBuild property that, when set totrue, suppresses all MVC-specific default directives from the synthetic import inMvcImportProjectFeature.Fixes #8259
Details
When enabled, the default import retains only the System
@usingdirectives:The following 11 MVC-specific directives are suppressed:
@using Microsoft.AspNetCore.Mvc.*directives@injectdirectives (IHtmlHelper, IJsonHelper, IViewComponentHelper, IUrlHelper, IModelExpressionProvider)@addTagHelperdirectives (UrlResolutionTagHelper, HeadTagHelper, BodyTagHelper)Explicit
@inject,@using, and@addTagHelperdirectives in.cshtmlor_ViewImports.cshtmlfiles continue to work regardless of this setting.Usage
Follow-up needed
A change in
dotnet/sdkis needed to add<CompilerVisibleProperty Include="SuppressMvcRazorImports" />so this property flows from MSBuild to the source generator. Until then, users can set it via.globalconfig:Changes
RazorConfiguration.csSuppressMvcRazorImportsbool parameter + equality/hashMvcImportProjectFeature.csRazorSourceGenerator.RazorProviders.csbuild_property.SuppressMvcRazorImportsRazorProjectInfoFactory.csRazorConfigurationFormatter.csObjectWriters.cs/ObjectReaders.csMvcImportProjectFeatureTest.csRazorSourceGeneratorTests.csRazorConfigurationSerializationTest.cs