2011-05-09 54 views
7

我正在尝试使用自定义T4模板将新控制器添加到MVC 3项目。 Scott Hanselman在http://www.hanselman.com/blog/ModifyingTheDefaultCodeGenerationscaffoldingTemplatesInASPNETMVC.aspx上写过我自己的模板,但我有兴趣在MvcTextTemplateHost类中进一步挖掘,以了解它还提供了什么,因此我们可以自定义一些更多的控制器,然后看看它是如何实现的与“添加控制器...”对话框进行交互。我在哪里可以找到MvcTextTemplateHost的API规范?

但是我找不到(在谷歌搜索之后,当然......)对这个类的引用,也没有MSDN或任何其他MS站点......任何想法?

感谢, 塞尔吉

回答

9
+0

这正是我在做什么,因为我发现,“添加控制器...”和“添加视图...”只可以做的工作:-) 的一部分无论如何,是否有意义从脚手架模板实例化MvcTextTemplateHost?如果是这样,它在哪个组装?谢谢,斯科特! – Sergi 2011-05-13 06:43:27

3
using Microsoft.VisualStudio.Web.Mvc.Scaffolding.BuiltIn; 
using Microsoft.VisualStudio.Web.Mvc.UserInterface; 

C:\ WINDOWS \ Microsoft.NET \装配\ GAC_MSIL \ Microsoft.VisualStudio.TextTemplating.10.0 \ v4.0_10.0.0.0__b03f5f7f11d50a3a \ Microsoft.VisualStudio.TextTemplating.10.0.dll Microsoft.VisualStudio .TextTemplating.10.0.dll

C:\ WINDOWS \ Microsoft.NET \装配\ GAC_MSIL \ Microsoft.VisualStudio.TextTemplating.10.0 \ v4.0_10.0.0.0__b03f5f7f11d50a3a \ Microsoft.VisualStudio.TextTemplating.10.0.dll 微软.VisualStudio.TextTemplating.Interfaces.10.0.dll

C:\ Program Files(x86)\ Microsoft Visua升工作室10.0 \ Common7 \ IDE Microsoft.VisualStudio.Web.Mvc.4.0.dll

如果添加论文作为你的ASP.NET MVC Web项目的引用并将其设置为正确的DLL为你的MVC版本(上面的dll参考)2.0 3.01 0r 4。0(仍为测试版)

您可以将T4代码(不是标签)复制到控制器中,并在MvcTextTemplateHost对象上提供智能感知和可调试性,以便设置正确的属性数据等等在创建和有意义的数据填充它,看看它在做什么(在理论上这将工作我希望)

以前如前所述在.net反射打开这些会透露一些信息。我没有看过MVCScaffolding的代码,它在我的待办事项列表上的codeplex上)。我现在的问题是在VS.NET 2010 T4中运行时在MvcTextTemplateHost中如何填充RelatedProperties以及如何填充它们。

还可以使用有形的T4编辑器的智能感知的。

5
public bool AddActionMethods { get; set; } 
internal ProjectItem AreaFolder { get; set; } 
public string AreaName { get; set; } 
public List<string> AssemblyPath { get; set; } 
public bool AutoEventWireup { get; set; } 
public List<string> ContentPlaceHolderIDs { get; set; } 
public Type ContextType { get; set; } 
public string ControllerName { get; set; } 
public string ControllerRootName { get; set; } 
public string EntitySetName { get; set; } 
public CompilerErrorCollection Errors { get; set; } 
[Dynamic] 
public object ExtendedProperties { [return: Dynamic] get; } 
public Encoding FileEncoding { get; set; } 
public string FileExtension { get; set; } 
public Version FrameworkVersion { get; set; } 
internal AppDomain GenerationAppDomain { get; set; } 
public bool IsContentPage { get; set; } 
public bool IsPartialView { get; set; } 
public string MasterPageFile { get; set; } 
IList<string> ITextTemplatingEngineHost.StandardAssemblyReferences { get; } 
IList<string> ITextTemplatingEngineHost.StandardImports { get; } 
public Type ModelType { get; set; } 
public string Namespace { get; set; } 
public string OutputFileExtension { get; set; } 
public IPluralizer Pluralizer { get; set; } 
public string PrimaryContentPlaceHolderID { get; set; } 
public PrimaryKey[] PrimaryKeys { get; set; } 
public bool ReferenceScriptLibraries { get; set; } 
public Dictionary<string, RelatedModel> RelatedProperties { get; set; } 
public string TemplateFile { get; set; } 
public Type ViewDataType { get; set; } 
public string ViewDataTypeName { get; set; } 
public string ViewName { get; set; } 
相关问题