When creating a new project for MVC3 I have an option to select a custom viewengine. I can choose between Razor and ASPX. Is there a way to add Spark to the dropdownlist?
问题:
回答1:
The short answer is: No, not really.
The long answer is: Yes, but there's a catch and it requires registry edits.
The New Project Dialog
is built around the idea of selecting a projecttemplate first and then selecting a view-engine supported by that template.
Others have managed to add their own things to this window, so I took the hints offered by ASP.NET MVC 3 with xUnit.net Testproject, another 3rd party extension and played around in the registry for a while.
First you have to create a ProjectTemplate for visual studio from which it can generate a clean Spark project. For completeness sake, you can do this by creating a new Razor project, rewiring it for Spark and then exporting the template using the file menu. Uncheck the box to auto-register the new export in VS. I opted to keep my installation simple and moved the new template to where the official MVC3 project templates live (For me that was C:\Program Files (x86)\Microsoft VisualStudio 10.0\Common\IDE\ProjectTemplates\CSharp\Web
). Then run "devenv /setup" from the commandline for VS to find and register the newly created template.
Custom additions to the New Dialogue Window have to be added here:
[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\10.0\Mvc3\ProjectTemplates]
|
|- [MyOwnTemplate]
|- (REG_SZ)Title="Template title"
|- (REG_SZ)Description="Description for the box in the right"
|- [C#]
|- [Spark]
| |- (REG_SZ)Path="CSharp\\Web"
| |- (REG_SZ)Template="YourCustomCSharpSparkTemplate.zip"
| |- (REG_DWORD)SupportsUnitTests=1
|- [Razor]
|- (REG_SZ)Path="CSharp\\Web"
|- (REG_SZ)Template="YourCustomCSharpRazorTemplate.zip"
|- (REG_DWORD)SupportsUnitTests=0
If you're not on a 64-bit installation, remove the Wow6432Node key from the opening registry node.
Now when you restart VS and run the New Project Dialog wizard for MVC3 the newly registered template should be listed in there. When you select your custom projecttemplate, you should see that the ViewEngine dropdown shows "Spark" as the current ViewEngine.
The New Project Dialog
groups templates by the top-key under ProjectTemplates. Since MVC3 does not register its default templates in the registry we don't know under which key they are grouped and consequently cannot add our own ViewEngines to those.
回答2:
You have to add T4 templates that add support for other view engines (including Spark). Here's a link that explains it: http://weblogs.asp.net/jacqueseloff/archive/2010/07/30/mvc-3-supporting-custom-view-engines.aspx