1

NOTE: I have looked at this link and disabled CustomTools and still receive this error: MvcTextTemplateHost not found

I am trying to create custom Views in one command for Create, Update, Details, Filter, and List operations. I am able to add them one at a time by right clicking and choosing New View, but when I type Scaffold AddView SampleModel I get the following error message:

The type or namespace name 'MvcTextTemplateHost' could not be found (are you missing a using directive or an assembly reference?).

The template file is AddView.cs.t4. I tried renaming it to .tt but I cannot get the Powershell to look for a .tt file. Any ideas?

Community
  • 1
  • 1
tehdoommarine
  • 1,868
  • 3
  • 18
  • 31

1 Answers1

3

MvcScaffolding uses its own custom template host and does not use the MvcTextTemplateHost. I would take a look at the T4 templates that are included with the MvcScaffolding NuGet package. The beginning of one of these templates is shown below.

<#@ Template Language="C#" HostSpecific="True" Inherits="DynamicTransform" #>
<#@ Output extension="aspx" #>
<# var viewDataType = (EnvDTE.CodeType) Model.ViewDataType; #>
Matt Ward
  • 47,057
  • 5
  • 93
  • 94
  • is there any difference between Model.ViewDataType and MvcTextTemplateHost? – tehdoommarine Sep 29 '11 at 20:06
  • 1
    Yes they are different. The Model and the Model.ViewDataType are different objects. MvcScaffolding builds up this dynamic model object (Model) based on the model you are trying to scaffold and adds extra properties that can be used in the T4 template. The Model.ViewDataType returns the type of your view. It is used to make your view strongly typed when the view is generated. There are lots of other properties available on this Model object which you can see being used in the T4 templates that are included with the MvcScaffolding NuGet package. – Matt Ward Sep 29 '11 at 20:57