-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Razor compilation APIs exposing Roslyn types being obsoleted in 2.2.0 and removed in 3.0.0 #4902
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
Comments
Hi @danroth27 I have below code so how can I change it accordingly to AddApplicationPart because AddApplicationPart require assembly to be pass in Full code var mvcBuilder = services
.AddMvc()
.AddJsonOptions(
options => options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore
)
.SetCompatibilityVersion(CompatibilityVersion.Version_2_2)
.AddRazorOptions(o =>
{
foreach (var module in modules)
{
o.AdditionalCompilationReferences.Add(
MetadataReference.CreateFromFile(module.Assembly.Location));
}
}); |
What do you use to create the passed in instance of |
@pranavkm I just added my code please check it. |
Looks like you're already adding the assembly as an application part on line 115. Removing the |
I have the same issue, just adding the aplicación part assembly does not register views and models from those compilations. |
In https://github.com/simplcommerce/SimplCommerce, with it's modular architecture, each module is a Razor Class Library. We manually load modules and then add them to the main web app using ApplicationPart. We also support theming, users can switch between the themes at run time. This feature required run time compilation of cshtml file. Adding ApplicationPart seems not work this scenario |
@MathiasKowoll here's the bit of code that's required to register assembly parts including the views assembly: https://github.com/pranavkm/PluginApp/blob/master/MainApp/Startup.cs#L74-L90
@thiennn can you be more precise about what does not work? I'd recommend filing a separate issue with a simple repro to show what's expected and what does not work. |
Using Core 2.2 I have an issue the same as #2126 which I solved this using @pranavkm 's solution on that issue (Aug 14, 2017). However, since MetadataReferenceFeature is being obsoleted, I am trying to rewrite so it doesn't use it. But it just brings back my original issue. I'm basically doing what @pranavkm 's other link says (https://github.com/pranavkm/PluginApp/blob/master/MainApp/Startup.cs#L74-L90) now, but it makes no difference, always get this error, unless using the workaround in issue 2126. [14:38:42 ERR] An unhandled exception has occurred while executing the request. A screenshot of Modular.Modules.Application1 sitting in mvcBuilder.PartManager.ApplicationParts, and having the path that it really exists at on disk. |
@camelofcode look at this bug #6215 |
@MathiasKowoll Thanks, that worked great - deleting the deps.json file for the dll fixes it. Not a surprise as my code is heavily inspired by @thiennn 's article here https://www.codeproject.com/Articles/1109475/Modular-Web-Application-with-ASP-NET-Core - so anything that fixes his problems likely helps me! |
@camelofcode You are welcome, my code is also heavily bases on @thiennn work. |
We periodically close 'discussion' issues that have not been updated in a long period of time. We apologize if this causes any inconvenience. We ask that if you are still encountering an issue, please log a new issue with updated information and we will investigate. |
As part of the 2.1.0 release, ASP.NET Core added support for build time compilation of cshtml files (Razor Views & Razor Pages). This feature is on by default and allows build time verification of the correctness of Razor files, and also faster startup performance. Additionally, MVC watches for changes to cshtml files and seamlessly updates build-time compiled views with runtime compiled views. This allows editing cshtml files and then refreshing the browser to see the changes.
MVC uses the app's compilation context, details about the references and settings that were used to compile the source code (.cs) in the app, to compile views at runtime. In addition to the compilation context, MVC exposes options such as RazorViewEngineOptions.CompilationCallback and AdditionalCompilationReferences that allow configuring compilation specifically for runtime.
Runtime specific customizations are unavailable at build time and consequently the two outputs could be different.
To address this inconsistency, we plan on removing APIs in MVC that change or modify runtime compilation. For 2.2.0, we're marking these APIs obsolete with the intent to remove them in 3.0.0. This is the list of affected APIs:
Properties on
Microsoft.AspNetCore.Mvc.Razor.RazorViewEngineOptions
AdditionalCompilationReferences
CompilationCallback
Microsoft.AspNetCore.Mvc.Razor.Compilation.MetadataReferenceFeature
Microsoft.AspNetCore.Mvc.Razor.Compilation.MetadataReferenceFeatureProvider
Microsoft.AspNetCore.Mvc.Razor.Compilation.RazorReferenceManager
No changes are required to your application if it does not use these APIs.
Apps using these APIs to add assembly references to the compilation context for runtime compilation should instead use
ApplicationPartManager.AddApplicationPart
to add application parts for each assembly reference, or switch to a built-time compilation model (see Create reusable UI using the Razor Class Library project).Other scenarios blocked by the removal of these APIs and not covered by alternative MVC features should raised here.
The text was updated successfully, but these errors were encountered: