Using VS2015 and MVC 5.2.3, I am trying to shift areas of functionality including Razor views to class libraries, so that I can share it between multiple projects.
I use the MvcBuildViews facility as typically described, and setup like the following, as it often catches typos before publishing:
<Target Name="MvcBuildViews" AfterTargets="AfterBuild" Condition="'$(MvcBuildViews)'=='true'">
<AspNetCompiler VirtualPath="temp" PhysicalPath="$(ProjectDir)" />
</Target>
This works fine with the main project itself, but I am having trouble getting it to work with the libraries.Instead, I get the following compiler error:
web.config(41): error ASPCONFIG: Could not load file or assembly 'System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
The referenced web.config section appears as below:
<system.web>
<compilation>
<assemblies>
<add assembly="System.Web.Mvc, Version=5.2.3.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
</assemblies>
</compilation>
<httpRuntime targetFramework="4.6"/>
</system.web>
All settings look very similar to the main project, and experimentation has been fruitless and keeps leading me back to this same basic error above. Required references are all set and the same as for the main project.
I understand the AspNetCompiler tag in the csproj is a wrapper for the aspnet_compiler.exe process, but I can't see what is different about the compilation environment in the class library compared to the main project.
Might it be possible to pass a specific assembly search folder to the compiler in this tag? - since the System.Web.Mvc.dll assembly certainly does exist, in the bin\Release folder of the class library project. Or is there a better approach?
Detailed information on the internal processes of aspnet_compiler.exe is scarce and it does not seem to have a verbose diagnostics mode.
How should I proceed with this?