3
votes

I have installed MvcScaffolding without any issues but when I try to execute a scaffold request I get the error "DbContext.Task.t4" does not exist along with other files that are missing. I have a model called Task which I think its referring to but I am at a loss on how I fix this error?

"Scaffold Controller Task -ModelType Task -ControllerName TasksController -DbContextType TasksDbContext"

Install-Package MvcScaffolding

  • PM> Install-Package MvcScaffolding
  • Attempting to resolve dependency 'T4Scaffolding (≥ 1.0.2)'.
  • Attempting to resolve dependency 'EntityFramework (≥ 4.1.10311.0)'.
  • Successfully installed 'MvcScaffolding 1.0.2'.
  • Successfully added 'MvcScaffolding 1.0.2' to MvcApplication1.

Error

  • PM> Scaffold Controller Task -ModelType Task -ControllerName TasksController -DbContextType TasksDbContext

Scaffolding TasksController...

Find-ScaffolderTemplate : Could not find template 'DbContext.Task.t4' below folders ['C:\Development\MVCPLTaskmanager\MvcApplication1\packages\T4Scaffolding.1 .0.2\tools\EFDbContext'] At line:1 char:23 + param($c, $a) return . <<<< $c @a + CategoryInfo : NotSpecified: (:) [Find-ScaffolderTemplate], Exception + FullyQualifiedErrorId : T4Scaffolding.Cmdlets.FindScaffolderTemplateCmdlet

Get-ProjectType : Cannot find a type matching the name 'MvcApplication1.Models.TasksDbContext'. Try specifying the fully-qualified type name, including namesp ace. At C:\Development\MVCPLTaskmanager\MvcApplication1\packages\T4Scaffolding.1.0.2\tools\EFDbContext\T4Scaffolding.EFDbContext.ps1:45 char:39 + $foundDbContextType = Get-ProjectType <<<< ($dbContextNamespace + "." + $DbContextType) -Project $Project + CategoryInfo : NotSpecified: (:) [Get-ProjectType], InvalidOperationException + FullyQualifiedErrorId : T4Scaffolding.Cmdlets.GetProjectTypeCmdlet

Invoke-Scaffolder : Created database context TasksDbContext, but could not find it as a project item At C:\Development\MVCPLTaskmanager\MvcApplication1\packages\MvcScaffolding.1.0.2\tools\Controller\MvcScaffolding.Controller.ps1:71 char:40 + $dbContextScaffolderResult = Scaffold <<<< DbContext -ModelType $foundModelType.FullName -DbContextType $DbContextType -Area $Area -Project $Projec t -CodeLanguage $CodeLanguage -BlockUi + CategoryInfo : NotSpecified: (:) [Invoke-Scaffolder], RuntimeException + FullyQualifiedErrorId : T4Scaffolding.Cmdlets.InvokeScaffolderCmdlet

ANSWER It turns out that my model's namespace needs to be the same as the MVC project. Once I changed the namespace the scaffolding worked.

1
Can you add the answer you have here as an answer below and accept it? This question is marked as unanswered in searches.Chris Moschini

1 Answers

0
votes

I had this same issue, but it was due to the model classes having errors in them, which caused them to not build. Thus there was no model matching the name I gave to scaffolding and it concluded that I hadn't used the correct namespace.

So...

  • Check your code for build errors
  • Make sure the namespace of your Models is the namespace of your Application