有誰知道我們如何使用來自nuget的EmbeddedResourceVirtualPathProvider包嗎?

[英]Any body know how we can use this EmbeddedResourceVirtualPathProvider package from nuget?


I am trying to separate my views, controllers and models in a separate DLL and then load them into my host application. When i Google it i found this EmbeddedResourceVirtualPathProvider or VirtualPathProvider may be the way we can do it but unfortunately not found any working sample application or may be anything else which can fulfill this requirement in a good way please let me know. I am using ASP.Net MVC 5 with razor view engine.

我正在嘗試在一個單獨的DLL中分離我的視圖、控制器和模型,然后將它們加載到我的主機應用程序中。當我谷歌的時候,我發現這個EmbeddedResourceVirtualPathProvider或者VirtualPathProvider可能是我們可以實現它的方式,但是不幸的是沒有找到任何工作樣例應用程序,或者其他任何可以以好的方式滿足這個需求的東西,請讓我知道。我用ASP。Net MVC 5和razor視圖引擎。

Thanks in advance.

提前謝謝。

1 个解决方案

#1


2  

It's better if you try it yourself and then ask questions about problems that you run into. StackOverflow isn't very good at handing out full solutions; we tend to help with specific problems.

如果你自己嘗試一下,然后問一些你遇到的問題,那就更好了。StackOverflow不擅長提供完整的解決方案;我們傾向於幫助解決特定的問題。

Is the EmbeddedResourceVirtualPathProvider quick-start guide enough to help you?

EmbeddedResourceVirtualPathProvider快速啟動指南是否足以幫助您?

A custom VirtualPathProvider for IIS - load views and assets from Embedded Resources in referenced assemblies . To get started, install into your ASP.NET web application via nuget:

一個用於IIS的自定義的虛擬路徑提供者,它可以從被引用的程序集的嵌入資源中加載視圖和資產。要開始,請安裝到您的ASP中。NET web應用程序,通過nuget:

Install-Package EmbeddedResourceVirtualPathProvider

安裝包EmbeddedResourceVirtualPathProvider

This will add some code into App_Start registering the provider.

這將向App_Start注冊提供程序添加一些代碼。

Move views and assets into other assemblies, maintaining folder structure. e.g.

將視圖和資產移動到其他程序集中,維護文件夾結構。如。

/MyAspNetApp/Views/Thing/Thing.cshtml -> /ThingComponent/Views/Thing/Thing.cshtml

/ MyAspNetApp /視圖/事/。cshtml - > / ThingComponent /視圖/事/ Thing.cshtml

And set the the files BuildAction as EmbbeddedResource. Make sure your assembly is referenced, and you're done!

並將文件BuildAction設置為EmbbeddedResource。確保您的程序集被引用,這樣就完成了!

By default, all assemblies in the appdomain are scanned. You can restrict this in App_Start\RegisterVirtualPathProvider.cs file. You can also map assemblies to their location on disk, so they [can be] refereshed when you edit the files during development.

默認情況下,將掃描appdomain中的所有程序集。您可以在App_Start\RegisterVirtualPathProvider中對此進行限制。cs文件。您還可以將程序集映射到它們在磁盤上的位置,以便在開發期間編輯文件時引用它們。


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2014/03/12/72ffb0ab51989b8644b6d0dd75865f1e.html



 
粤ICP备14056181号  © 2014-2021 ITdaan.com