简体   繁体   English

如何跨多个项目共享cshtml页面?

[英]How to share cshtml pages across multiple projects?

I have a couple of pages common across all my ASP.NET projects. 我在所有ASP.NET项目中都有几个页面。 I would like to centralize that code inside a single assembly. 我想将该代码集中在一个程序集中。 How can I achieve this? 我怎样才能做到这一点? Is it possible to simply create and assembly and add it as a reference of my ASP.NET projects and the pages are going to be accessible? 是否可以简单地创建和组装并将其添加为我的ASP.NET项目的参考,并且页面将是可访问的?

Using razor views from a different (so from outside the web project) is not supported out of the box. 不支持使用来自不同的剃刀视图(因此来自Web项目外部)。 However there a tool to precompile razor views and then you can put them in any dll. 但是有一个预编译剃刀视图的工具,然后你可以将它们放在任何DLL中。 This custom tool is called RazorGenerator . 此自定义工具称为RazorGenerator

There are some blog posts where you can start: 有一些博客文章,你可以开始:

Precompile your MVC Razor views using RazorGenerator 使用RazorGenerator预编译MVC Razor视图
Compile your asp.net mvc Razor views into a seperate dll 将你的asp.net mvc Razor视图编译成一个单独的dll

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

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