简体   繁体   English

ASP.NET 5 / MVC6中的VirtualPathProvider等价物?

[英]VirtualPathProvider equivalent in ASP.NET 5/MVC6?

I'm looking at migration strategies for an ASP4/MVC4 application into ASP5/MVC6. 我正在研究将ASP4 / MVC4应用程序迁移到ASP5 / MVC6的迁移策略。 Our current implementation relies on loading cshtml views as embedded resources from DLL's, and we use a VirtualPathProvider to find these cshtml files. 我们当前的实现依赖于将cshtml视图作为DLL的嵌入资源加载,我们使用VirtualPathProvider来查找这些cshtml文件。

Unfortunately, HostingEnvironment.RegisterVirtualPathProvider seems to be gone from MVC6. 不幸的是,HostingEnvironment.RegisterVirtualPathProvider似乎已经从MVC6中消失了。 The closest thing I can find is IEnvironment.WebRootFileProvider, which is an IFileProvider. 我能找到的最接近的是IEnvironment.WebRootFileProvider,它是一个IFileProvider。 So I coded up a test class to see if it would work, and unfortunately, the IFileProvider I coded up is never queried for CSHTML files. 所以我编写了一个测试类来查看它是否可行,不幸的是,我编写的IFileProvider永远不会查询CSHTML文件。 I get requests for all of the .JS, .CSS, etc files, but no .CSHTML's. 我收到所有.JS,.CSS等文件的请求,但没有.CSHTML的请求。

What I'm looking for here is the ability to hook into the razor engine and provide a CSHTML file loaded from an embedded resource (or really, any other source for that matter) when a view is requested. 我在这里寻找的是能够挂钩剃刀引擎并在请求视图时提供从嵌入式资源(或实际上,任何其他来源)加载的CSHTML文件。 What should I be looking at here? 我应该在这看什么?

Thanks! 谢谢!

Alright, I figured it out by digging around in the source code. 好吧,我通过在源代码中挖掘来解决这个问题。 I can load views from wherever I want by overriding the File Provider on the Razor View Engine options class: 我可以通过覆盖Razor View Engine选项类上的文件提供程序来从任何我想要的地方加载视图:

            services.AddMvc().AddRazorOptions(x => x.FileProvider = new EmbeddedFileProvider(typeof(Startup).Assembly));

Now the only problem I see is that there appears to be no way to embed resources in an ASP.NET 5 DLL via Visual Studio... 现在唯一的问题是,似乎没有办法通过Visual Studio将资源嵌入到ASP.NET 5 DLL中......

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM