8

I have a couple of pages common across all my ASP.NET projects. 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?

Martin
  • 39,309
  • 62
  • 192
  • 278
  • Possible duplicate. You can achieve the same result for cshtml files etc. http://stackoverflow.com/questions/1116465/how-do-you-share-code-between-projects-solutions-in-visual-studio – Lloyd Feb 15 '12 at 20:44
  • This is not a duplicate. I am not trying to link code. I want a shared library for ASP.NET pages. – Martin Feb 15 '12 at 20:47
  • Did you read the second answer about linking files? Also asnwered here. http://stackoverflow.com/questions/5136128/asp-net-mvc-how-can-i-add-views-scripts-and-content-files-as-links-in-order-to – Lloyd Feb 15 '12 at 20:52
  • Yes, I did. I need the code in its own library. – Martin Feb 15 '12 at 20:55
  • Did you manage to get closer to any solution on this? I am experiencing the same needs. Third party needs to code content, so to avoid sharing the "root" code, it would be nice to have it all in a shared library for them to include. – Mats Magnem Apr 08 '14 at 17:15
  • 1
    Include the view as EmbeddedResource and use EmbededdedResourceVirtualPathProvider – mcintyre321 Sep 17 '15 at 12:45

1 Answers1

4

Using razor views from a different (so from outside the web project) is not supported out of the box. However there a tool to precompile razor views and then you can put them in any dll. This custom tool is called RazorGenerator.

There are some blog posts where you can start:

Precompile your MVC Razor views using RazorGenerator
Compile your asp.net mvc Razor views into a seperate dll

nemesv
  • 138,284
  • 16
  • 416
  • 359