如何在ASP.NET Core MVC中重用视图(页面)?

问题描述:

在ASP.NET Core MVC之前,我们将使用RazorGenerator将视图编译为程序集,并通过引入自定义ViewEngine从其他程序集而不是文件系统中加载视图,在其他项目中重用这些视图.

Before ASP.NET Core MVC, we would use RazorGenerator to compile views into assemblies, and we would reuse those views in another project, by introducing a custom ViewEngine that would load the view from the assembly instead of file-system.

在ASP.NET Core MVC中,存在预编译视图的概念,它在2.0版本中是开箱即用的,并创建一个约定为 project_name的程序集.PrecompiledViews.dll .

In ASP.NET Core MVC there is this concept of pre-compiled views and it works out of the box for version 2.0 and creates an assembly that by convention has the name of project_name.PrecompiledViews.dll.

我有两个问题,尽管我在Google上找不到答案. 首先,我不知道如何在另一个项目中重用该DLL.就像我在CompanyBase.dll中有About.cshtml页面一样,如何在ProjectAlpha中重用该页面/视图?

I have two problems though that I can't find an answer for on Google. First I don't know how to reuse that DLL in another project. Like if I have About.cshtml page in CompanyBase.dll, how can I reuse that page/view in ProjectAlpha?

而且我也不想在发布时进行视图编译.我该如何更改它才能在构建中发生?

And also I don't want view compilation to happen on publish. How can I change it to happen on build?