Skip to content

Razor SDK shouldn't generate the MVC recompilation attributes unless its necessary #8161

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
rynowak opened this issue Mar 4, 2019 · 4 comments
Assignees
Labels
area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates bug This issue describes a behavior which is not expected - a bug. Done This issue has been fixed

Comments

@rynowak
Copy link
Member

rynowak commented Mar 4, 2019

Describe the bug

A web SDK project that targets netcoreapp3.0 with no razor files will unconditionally have these attributes:

[assembly: Microsoft.AspNetCore.Mvc.ApplicationParts.RelatedAssemblyAttribute("SampleApp.Views")]
[assembly: Microsoft.AspNetCore.Razor.Hosting.RazorLanguageVersionAttribute("3.0")]
[assembly: Microsoft.AspNetCore.Razor.Hosting.RazorConfigurationNameAttribute("MVC-3.0")]
[assembly: Microsoft.AspNetCore.Razor.Hosting.RazorExtensionAssemblyNameAttribute("MVC-3.0", "Microsoft.AspNetCore.Mvc.Razor.Extensions")]

This adds extra runtime references to types that are probably not used.

This logic needs to be updated to consider whether you have any .cshtml files, and/or be based on some explicit gesture in the project file, or just obsoleted.

Basing this on the presence of .cshtml files could cause issues in the case will cause issues in the following cases:

  1. You have no cshtml files at build time, and you are using runtime compilation when published
  2. Youe application is an F#/VB project, referencing class libraries for views, and you are using runtime compilation

It's also an impactful change, because it requires evaluating an item group to evaluate a property, which means that it has to be in a target.


The RelatedAssemblyPartAttibute is purely for discovery of compiled views/pages and should be made conditional without reservation.

The Razor.Hosting attributes are for the settings used by runtime compilation. We could consider obsoleting these now that runtime compilation is outside the shared framework. However - we need to consider the impact on downlevel. If this logic is inside the Razor.Design package in 2.1/2.2 we can remove it from the SDK and say that it's not needed/supported in 3.0.

@rynowak
Copy link
Member Author

rynowak commented Mar 4, 2019

/cc @pranavkm

@rynowak rynowak added area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates bug This issue describes a behavior which is not expected - a bug. labels Mar 4, 2019
@mkArtakMSFT mkArtakMSFT added this to the 3.0.0-preview5 milestone Mar 4, 2019
@mkArtakMSFT
Copy link
Member

Closing this based on the work happening in the linked issue, where we will introduce a dedicated flag on the project level, which will indicate whether those attributes should be generated or not.

@rynowak rynowak reopened this Mar 12, 2019
@rynowak
Copy link
Member Author

rynowak commented Mar 12, 2019

That doesn't address this issue.

@pranavkm
Copy link
Contributor

pranavkm commented Apr 4, 2019

This is needed in preview4 (at least with the current state of things).The WebSDK specifies AddRazorSupportForMvc. Some Blazor templates reference the WebSDK, so you now get compilation errors stating it can't find Mvc.

pranavkm added a commit to dotnet/razor that referenced this issue Apr 4, 2019
* Do not generate MVC attributes unless necessary
Fixes dotnet/aspnetcore#8161
@pranavkm pranavkm added Done This issue has been fixed and removed 2 - Working labels Apr 4, 2019
@ghost ghost locked as resolved and limited conversation to collaborators Dec 3, 2019
JunTaoLuo pushed a commit that referenced this issue May 7, 2020
JunTaoLuo pushed a commit that referenced this issue May 17, 2020
dougbu pushed a commit to dougbu/razor-compiler that referenced this issue Nov 17, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates bug This issue describes a behavior which is not expected - a bug. Done This issue has been fixed
Projects
None yet
Development

No branches or pull requests

3 participants