开发者

Where can I find the API specification for MvcTextTemplateHost?

开发者 https://www.devze.com 2023-03-04 12:41 出处:网络
I\'m trying to use a custom T4 template for adding new Controllers to a MVC 3 project. I have my own templa开发者_JAVA百科te as Scott Hanselman wrote on http://www.hanselman.com/blog/ModifyingTheDefau

I'm trying to use a custom T4 template for adding new Controllers to a MVC 3 project. I have my own templa开发者_JAVA百科te as Scott Hanselman wrote on http://www.hanselman.com/blog/ModifyingTheDefaultCodeGenerationscaffoldingTemplatesInASPNETMVC.aspx, but I'm interested in digging a bit more in the MvcTextTemplateHost Class to see what else it offers, so we can customize a bit more our controllers, and see how does it interact with the "Add controller..." dialog.

But I cannot find (after searching at Google, of course...) the reference to this class, nor MSDN either any other MS site... any ideas?

Thanks, Sergi


You'll find that this is only extensible to a point. Instead spend time with the new MvcScaffolding package from Steven Sanderson. He's extended this original stuff WAY WAY beyond my plans.

  • Introduction: Scaffold your ASP.NET MVC 3 project with the MvcScaffolding package
  • Standard usage: Typical use cases and options
  • One-to-Many Relationships
  • Scaffolding Actions and Unit Tests
  • Overriding the T4 templates
  • Creating custom scaffolders
  • Scaffolding custom collections of files


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; }


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

If you add theses as references to your ASP.NET MVC Web project and set it to the correct dll for your MVC version (last dll reference above) 2.0 3.01 0r 4.0 (still Beta)

You can copy the T4 code (not the tags) in and run it in a controller which will give intellisense and debugability you would need to set the right properties data and so on, on the MvcTextTemplateHost object on creation and populate it with meaningful data to see what it is doing (in theory this will work I hope)

As previously stated opening these in .NET Reflector will divulge some info. I have not looked into the code of MVCScaffolding the source is on codeplex its on my todo list). Question i have at the moment is what with and how are the RelatedProperties populated in the MvcTextTemplateHost when it runs in VS.NET 2010 T4.

Also can make use of Tangible T4 Editor for intellisense.


Reflector would be your best option. It allows you to decompile the DLL. You can download it directly at http://shop.reflector.net/download.


This is the closest thing to a spec we have but it is way out of date: http://blogs.msdn.com/b/webdevtools/archive/2009/01/29/t4-templates-a-quick-start-guide-for-asp-net-mvc-developers.aspx

You can use reflection or, you could take a look at the view templates, especially the identical helper methods at the bottom of each file, to see most of what is available in the MvcTextTemplateHost class.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号