View reuse for MVC

So I have inheritied a program (APPLE) whose code baseline originated on another program (ORANGE). In order to make it easier for multiple teams to update this code we are moving the ‘common’ stuff out into a Shared Project (TREE). So far, we have made this work great with pulling out the Models and Controllers to a Shared library (obviously a few Models/Controllers remain in ORANGE as they are specific to that application).

However, I’m hitting a wall on how to extract the Views. The idea would be that the Shared Library (TREE) contains the common views (like file import, and landing page) while leaving the program specific code behind in the ‘main’ application (APPLE/ORANGE).

I found this article which looked really good. Except 1) I don’t have Microsoft.AspNetCore Nuget (My Microsoft.AspNet.[package] don’t appear to have ViewComponent), 2) When creating a new Web MVC project, it doesn’t have a wwwroot, Program.cs, or the .json files. I also found another article talking about using VirtualFiles, but it doesn’t really indicate where the EmbeddedResource class would reside, and (I could be mis-understanding) but it seems to look for all the Views in the vitural location.

So what is the best way to split common views out into the Shared Project I’ve created and utilize them in our program application?

This is an application using MVC. It is not a Razor application.

I have access to Microsoft.AspNet.(various packages) and DevExpress.(various packages), but must go through a process to obtain other packages (so I can’t easily download a package and test out suggestions).


Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

You could simply make your own NuGet package which, when installed into any project, adds the shared views, controllers and any other files you want.

We’ve done that successfully in my organisation to effectively provide a base template for any new MVC applications. It adds certain specific views and templates, overrides the layout view, sets up a controller and adds some global filters. It also adds some CSS and JavaScript files, so we’ve got ready-made corporate branding on the app, consistent shared functionality provided, and so on. It also depends on some other of our nuget packages which are then also loaded into the project, which provide shared functionality such as error handling, logging services, pre-made data connections, an API client and other bits and pieces which we need in almost every app we write.

The package itself is built from a separate project which is also source-controlled like any other codebase, and we maintain numbered versions.

This works very well as a way of sharing code and components between projects. It also means that any updates can be pushed out to all applications with minimal fuss.

Your nuget package could be installed manually into the project, or served from your own feed – you can create private NuGet feeds in Azure DevOps and other places, or even just a folder on a shared drive can be used as a package source, if you have to.

(P.S. That article you’ve linked to is about .NET Core, whereas you’re using .NET Framework. The project structures are significantly different, hence your confusion.)

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Notify of

Inline Feedbacks
View all comments
Would love your thoughts, please comment.x