-
Notifications
You must be signed in to change notification settings - Fork 25.2k
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
RazorViewEngineOptions for FileProviders in ASP.NET Core 3.0 #14593
Comments
This topic+sample was updated for 3.0 on #14027. I'll take a look, but I'm 🏃 at the moment and won't be able to get to this for perhaps a week or two. |
5.5 K PV/month. |
Ah... 3.0 could solve it? |
Perhaps this solution will work. .NET Core 2 by installing Microsoft.AspNetCore.Mvc.Razor nuget package services.Configure<RazorViewEngineOptions>(options => {
options.FileProviders.Clear();
options.FileProviders.Add(new PhysicalFileProvider(appDirectory));
}); .NET Core 3 by installing Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation nuget package services.Configure<MvcRazorRuntimeCompilationOptions>(options => {
options.FileProviders.Clear();
options.FileProviders.Add(new PhysicalFileProvider(appDirectory));
}); |
services.Configure<Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation.MvcRazorRuntimeCompilationOptions>(options => MvcRazorRuntimeCompilationOptions is also not work. |
for me, MvcRazorRuntimeCompilationOptions also doesn't work, although I can successfully add the code and it throws no error, the views are not found during runtime. |
After a lot of searching managed to solve it, the above code stated is correct. But you will also need to change |
This is misplaced here ... my bad. This is for the View Complication topic, where some of the updates for 3.0 were made and one update doesn't seem correct based on the announcement. I'll move this issue over and ping all of you on the new issue. |
how to run app-parts correct .net core 3.0? the demo dosen't not work well for .net core 3.0 Maybe they are the seem question #14800 ? |
Trying this but get a ton of errors. I've already put in my csproj the suggested value... One or more compilation references may be missing. If you're seeing this in a published application, set 'CopyRefAssembliesToPublishDirectory' to true in your project file to ensure files in the refs directory are published. ... thousands of missing type errors ... |
Going back to .net core 2.2, this is a mess... |
@jjxtra can you open an issue at https://github.com/aspnet/AspNetCore with the simplest possible repo? This is a closed issue in the doc's repo, not the asp.net core code repo. |
After doing that, I get a new exception : |
The same issue, app-parts with razor views can't work in .net core 3.0. |
There is some voodoo involved, I have solved most of it with this (except unit testing razor) here: dotnet/aspnetcore#14952 |
@Tratcher what's the trick to get the following code to compile in 3.0?
'RazorViewEngineOptions' does not contain a definition for 'FileProviders' and no accessible extension method 'FileProviders' accepting a first argument of type 'RazorViewEngineOptions' could be found |
Never mind |
@serpent5 now I get |
Have you got it working now? |
No |
You need the using System.Reflection;
using Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation;
using Microsoft.Extensions.FileProviders; Here's the code itself for completeness: services.Configure<MvcRazorRuntimeCompilationOptions>(options =>
{
options.FileProviders.Add(
new EmbeddedFileProvider(typeof(MySharedController).GetTypeInfo().Assembly));
}); |
yes,it's ok.
All of
https://github.com/aspnet/AspNetCore.Docs/tree/master/aspnetcore/mvc/advanced/app-parts |
Moved from #14586 (EDIT by @guardrex to place code block into remark).
@zhou881117 remarks ...
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
The text was updated successfully, but these errors were encountered: