I have several MVC projects in one solution.
Following this accepted answer: "Add as Link" for folders in Visual Studio projects, I am attempting to reuse .cshtml views across these proejcts by placing reusable views in a base project. So far, I have set up location formats in the "consuming" projects for the view-engine like this:
var locationFormats = new string[]
{
"~/Views/{1}/{0}.cshtml",
"~/Views/Shared/{0}.cshtml",
"~/Views/Common/{1}/{0}.cshtml",
"~/Views/Common/Shared/{0}.cshtml"
};
I have set up a recursive, linked directory in consuming projects' .csproj
files to include common views like this:
<ItemGroup>
<Content Include="..\..\..\common.cms\CommonViews\**\*.*">
<Link>\Views\Common\%(RecursiveDir)%(FileName)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
...and all the views are appearing in the consuming projects with the linked-file/cshtml(@) icon, so the paths are correct. For example, the following file is very clearly present in my test consuming project:
\Views\Common\Home\Index.cshtml
But when I run the project, I'm getting:
The view 'Index' or its master was not found or no view engine supports the searched locations. The following locations were searched:
~/Views/Home/Index.cshtml
~/Views/Shared/Index.cshtml
~/Views/Common/Home/Index.cshtml
~/Views/Common/Shared/Index.cshtml
Question
So I am wondering: is it even possible to link views in this way? What is missing, or what could be inhibiting this from working?
More generally, what about any non-compiled files I'd like to share? Is this technique never going to work?