Background: I am attempting to create a new C# project template for ASP.NET MVC using Visual Studio 2013 Ultimate Update 5. To start, I create an Web application from the empty template and include MVC references. Then, I add all of the basic required components for the application such as the model, controller, and views. Next, I run it, and it works. Then, I export it as a project template.
In the past, I have successfully created templates for Web Api and Console Apps using the above method.
Problem Description: When I attempt to use the template for a new project, I get the following error:
According to both the error message and Microsoft, I should be able to resolve this by placing the following code within my Web.config file:
<system.web>
<compilation debug="true" targetFramework="4.5.1"/>
<httpRuntime targetFramework="4.5.1"/>
</system.web>
However, this is already present, and the dialogue box persists.
If I try to run without debugging, I get the following error in the browser:
HTTP Error 500.19 - Internal Server Error
The requested page cannot be accessed because the related configuration data for the page is invalid.
Attempts to solve:
Update:
Rather than using Export Template within Visual Studio, I have installed TemplateBuilder and SideWaffle and have followed the linked video instructions for constructing a custom project template. However, I get the following error when trying to create a new project from the template:
This error has been an open issue within github since April, so it appears I am out of luck.
Second Update: Root Cause Analysis
I have determined the root cause for why projects based on the exported template fail. Comparing the references of the base and derived projects reveals the following:
Derived:
<Reference Include="System.Web.Razor">
<HintPath>..\..\..\..\..\..\Program Files (x86)\Microsoft ASP.NET\ASP.NET Web Pages\v2.0\Assemblies\System.Web.Razor.dll</HintPath>
</Reference>
Base:
<Reference Include="System.Web.Razor">
<HintPath>..\packages\Microsoft.AspNet.Razor.3.2.3\lib\net45\System.Web.Razor.dll</HintPath>
</Reference>
Once the HintPaths in the derived project are reset to those of the base, the derived project runs successfully (No "Debugging Not Enabled" dialogue box).
The question becomes: "How can I ensure the HintPaths of the derived project are set to the appropriate values automatically?"
I was able to create a working MVC template using the following methods:
In the base project:
In the csproj file, the references to the MVC related dlls are in the following form:
<Reference Include="System.Web.Razor">
<HintPath>\\BILL\Users\Popper\Desktop\Stackoverflow\UNCPathNonSpecificPrivateReferences\packages\Microsoft.AspNet.Razor.3.2.3\lib\net45\System.Web.Razor.dll</HintPath>
<SpecificVersion>False</SpecificVersion>
<Private>True</Private>
</Reference>
In particular, the UNC path to the dll prevents HintPath from being overwritten.
In the derived project:
After saving and building, I close and reopen the project.