将自定义视图引擎添加到“新项目”对话框中?
当为 MVC3 创建新项目时,我可以选择自定义视图引擎。我可以在 Razor 和 ASPX 之间进行选择。有没有办法将 Spark 添加到下拉列表中?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
简短的回答是:不,不是。
长的答案是:是的,但有一个问题,它需要注册表编辑。
新建项目对话框
的构建理念是首先选择项目模板,然后选择该模板支持的视图引擎。其他人已经设法将自己的东西添加到这个窗口中,所以我接受了 ASP.NET MVC 3 与 xUnit.net Testproject,另一个第 3 方扩展,并在注册表中运行了一段时间。
首先,您必须为 Visual Studio 创建一个 ProjectTemplate,从中它可以生成一个干净的 Spark 项目。为了完整起见,您可以通过创建一个新的 Razor 项目,为 Spark 重新连接它,然后使用文件菜单导出模板来完成此操作。取消选中该框可在 VS 中自动注册新导出。我选择保持安装简单,并将新模板移至官方 MVC3 项目模板所在的位置(对我来说,这是 C:\Program Files (x86)\Microsoft VisualStudio 10.0\Common\IDE\ProjectTemplates\CSharp\Web )。然后从 VS 命令行运行“devenv /setup”来查找并注册新创建的模板。
必须在此处添加新对话窗口的自定义添加内容:
如果您不是使用 64 位安装,请从打开的注册表节点中删除 Wow6432Node 项。
现在,当您重新启动 VS 并运行 MVC3 的“新建项目对话框”向导时,新注册的模板应该会在其中列出。当您选择自定义项目模板时,您应该会看到 ViewEngine 下拉列表显示“Spark”作为当前 ViewEngine。
新建项目对话框
按ProjectTemplates 下的顶键对模板进行分组。由于 MVC3 不在注册表中注册其默认模板,我们不知道它们被分组在哪个键下,因此无法将我们自己的 ViewEngine 添加到其中。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:
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.您必须添加 T4 模板来添加对其他视图引擎(包括 Spark)的支持。这是解释它的链接: http://weblogs.asp.net/jacqueseloff/archive/2010/07/30/mvc-3-supporting-custom-view-engines.aspx
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