【问题标题】:Where can I find the API specification for MvcTextTemplateHost?在哪里可以找到 MvcTextTemplateHost 的 API 规范?
【发布时间】:2011-05-09 15:12:43
【问题描述】:

我正在尝试使用自定义 T4 模板将新控制器添加到 MVC 3 项目。我有自己的模板,正如 Scott Hanselman 在 http://www.hanselman.com/blog/ModifyingTheDefaultCodeGenerationscaffoldingTemplatesInASPNETMVC.aspx 上所写的那样,但我有兴趣在 MvcTextTemplateHost 类中挖掘更多内容,看看它还提供了什么,所以我们可以自定义更多我们的控制器,看看它是如何与“添加控制器...”对话框交互的。

但我找不到(当然是在 Google 上搜索之后……)对此类的引用,也找不到 MSDN 或任何其他 MS 站点……有什么想法吗?

谢谢, 塞尔吉

【问题讨论】:

    标签: asp.net-mvc-3 t4


    【解决方案1】:

    【讨论】:

    • 这正是我所做的,因为我发现“添加控制器...”和“添加视图...”只能完成部分工作:-)从脚手架模板实例化 MvcTextTemplateHost 有意义吗?如果是这样,它在哪个组件中?谢谢,斯科特!
    【解决方案2】:
    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; }
    

    【讨论】:

      【解决方案3】:
      using Microsoft.VisualStudio.Web.Mvc.Scaffolding.BuiltIn;
      using Microsoft.VisualStudio.Web.Mvc.UserInterface;
      

      C:\Windows\Microsoft.NET\assembly\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\assembly\GAC_MSIL\Microsoft.VisualStudio.TextTemplating.10.0\v4.0_10.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.TextTemplating.10.0.dll Microsoft.VisualStudio.TextTemplating.Interfaces.10.0.dll

      C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE Microsoft.VisualStudio.Web.Mvc.4.0.dll

      如果您将这些作为引用添加到您的 ASP.NET MVC Web 项目并将其设置为您的 MVC 版本的正确 dll(上面的最后一个 dll 引用)2.0 3.01 0r 4.0(仍然是 Beta)

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

      如前所述,在 .NET Reflector 中打开这些会泄露一些信息。我还没有查看 MVCScaffolding 的代码,源代码位于我的待办事项列表中的 codeplex 上)。我目前的问题是,在 VS.NET 2010 T4 中运行时,MvcTextTemplateHost 中的相关属性是什么以及如何填充。

      还可以使用 Tangible T4 Editor 进行智能感知。

      【讨论】:

        【解决方案4】:

        反射器将是您的最佳选择。它允许您反编译 DLL。可以直接在http://shop.reflector.net/download下载。

        【讨论】:

          【解决方案5】:

          这是最接近我们现有规范的东西,但它已经过时了:http://blogs.msdn.com/b/webdevtools/archive/2009/01/29/t4-templates-a-quick-start-guide-for-asp-net-mvc-developers.aspx

          您可以使用反射,或者您可以查看视图模板,尤其是每个文件底部的相同辅助方法,以查看 MvcTextTemplateHost 类中的大部分可用内容。

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 2014-12-07
            • 2022-08-16
            • 1970-01-01
            • 1970-01-01
            • 2018-11-11
            • 1970-01-01
            • 1970-01-01
            • 2023-04-10
            相关资源
            最近更新 更多