NuGet模块中的MVC视图(MVC Views in NuGet Modules)

编程入门 行业动态 更新时间:2024-10-21 06:00:00
NuGet模块中的MVC视图(MVC Views in NuGet Modules)

在为我公司的内部重用库制作NuGet模块时,我终于着手制作一个带有可视组件的模块。 此模块的.cshtml文件将驻留在特定于模块的位置(而不是标准的“Views”文件夹),因此我将一个辅助web.config放在与视图相同的文件夹中以允许MVC和Razor。

问题变了,虽然我可以在我的.nuspec文件中指定一个MVC版本作为依赖项,但我不希望必须是特定于版本的,因为我在我的视图中使用的所有功能都存在于所有版本的MVC中。

有没有办法可以查看特定(和非传统)文件夹并使用共享MVC二进制文件和配置进行操作? 是否可以在所有类型的项目中执行此操作,而无需在安装NuGet软件包后执行任何额外的步骤?

In making NuGet modules for my company's internal re-use library I finally embarked on making a module with a visual component. The .cshtml file for this module will reside in a location specific to modules (not the standard "Views" folder) so I have been putting a secondary web.config in the same folder with the view to allow for MVC and Razor.

The problem becomes, although I can specify a version of MVC as a dependency in my .nuspec file, I don't want to have to be version specific being that all the functionality I am using in my views exists in all versions of MVC.

Is there a way I can get a view into a specific (and non-traditional) folder and have it operate using shared MVC binaries and configuration? Is it possible to do this in all types of projects without requiring any extra steps for a person to take after installing the NuGet package?

最满意答案

你有几个选择:

使用razor生成器将视图编译到类中 - https://razorgenerator.codeplex.com 将视图包含为嵌入资源并编写VirtualPathProvider以获取它们(例如, 请访问http://www.ianmariano.com/2013/06/11/embedded-razor-views-in-mvc-4/ ) 在nuget包内部创建PowerShell脚本以及其他步骤

依赖于Asp.Net MVC的问题在于它并不总是向后兼容,但是你必须自己检查一下

You have few options:

Use razor generator to compile views into classes - https://razorgenerator.codeplex.com Include views as embedded resources and write VirtualPathProvider to get them ( example at http://www.ianmariano.com/2013/06/11/embedded-razor-views-in-mvc-4/) Inside nuget package create PowerShell script with additional steps

The problem with dependency into Asp.Net MVC is that it wasn't always backwards compatible, but this you will have to check yourself

更多推荐

MVC,NuGet,电脑培训,计算机培训,IT培训"/> <meta name="description" c

本文发布于:2023-08-07 08:48:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1463771.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:视图   模块   NuGet   MVC   Modules

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!