Scaffolding controllers with repositories in Mvc5, EF6, VisualStudio 2013

Maximo Dominguez picture Maximo Dominguez · Sep 29, 2013 · Viewed 7.6k times · Source

In vs2012 I used to use Steve Sanderson's mvcScaffolding Package with this package I could scaffold Action Methods with unit tests and controllers with repositories and dependency injection. My question is simple. Is there a way to do so in vs2013? When I install the package in vs2013 I get the following errors:

Set-DefaultScaffolder : Cannot get an instance of EnvDTE.DTE
At C:\dev\WebApplication2\packages\T4Scaffolding.Core.1.0.0\tools\init.ps1:50 char:9
+         Set-DefaultScaffolder -Name CustomTemplate -Scaffolder T4Scaffolding.Cus ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Set-DefaultScaffolder], InvalidOperationException
    + FullyQualifiedErrorId : T4Scaffolding.Cmdlets.SetDefaultScaffolderCmdlet

Set-DefaultScaffolder : Cannot get an instance of EnvDTE.DTE
At C:\dev\WebApplication2\packages\T4Scaffolding.Core.1.0.0\tools\init.ps1:51 char:9
+         Set-DefaultScaffolder -Name CustomScaffolder -Scaffolder T4Scaffolding.C ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Set-DefaultScaffolder], InvalidOperationException
    + FullyQualifiedErrorId : T4Scaffolding.Cmdlets.SetDefaultScaffolderCmdlet

Set-DefaultScaffolder : Cannot get an instance of EnvDTE.DTE
At C:\dev\WebApplication2\packages\T4Scaffolding.1.0.8\tools\init.ps1:6 char:1
+ Set-DefaultScaffolder -Name DbContext -Scaffolder T4Scaffolding.EFDbContext -Sol ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Set-DefaultScaffolder], InvalidOperationException
    + FullyQualifiedErrorId : T4Scaffolding.Cmdlets.SetDefaultScaffolderCmdlet

Set-DefaultScaffolder : Cannot get an instance of EnvDTE.DTE
At C:\dev\WebApplication2\packages\T4Scaffolding.1.0.8\tools\init.ps1:7 char:1
+ Set-DefaultScaffolder -Name Repository -Scaffolder T4Scaffolding.EFRepository -S ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Set-DefaultScaffolder], InvalidOperationException
    + FullyQualifiedErrorId : T4Scaffolding.Cmdlets.SetDefaultScaffolderCmdlet

Set-DefaultScaffolder : Cannot get an instance of EnvDTE.DTE
At C:\dev\WebApplication2\packages\MvcScaffolding.1.0.9\tools\init.ps1:47 char:1
+ Set-DefaultScaffolder -Name Controller -Scaffolder MvcScaffolding.Controller -So ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Set-DefaultScaffolder], InvalidOperationException
    + FullyQualifiedErrorId : T4Scaffolding.Cmdlets.SetDefaultScaffolderCmdlet

Set-DefaultScaffolder : Cannot get an instance of EnvDTE.DTE
At C:\dev\WebApplication2\packages\MvcScaffolding.1.0.9\tools\init.ps1:48 char:1
+ Set-DefaultScaffolder -Name Views -Scaffolder MvcScaffolding.Views -SolutionWide ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Set-DefaultScaffolder], InvalidOperationException
    + FullyQualifiedErrorId : T4Scaffolding.Cmdlets.SetDefaultScaffolderCmdlet

Set-DefaultScaffolder : Cannot get an instance of EnvDTE.DTE
At C:\dev\WebApplication2\packages\MvcScaffolding.1.0.9\tools\init.ps1:49 char:1
+ Set-DefaultScaffolder -Name Action -Scaffolder MvcScaffolding.Action -SolutionWi ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Set-DefaultScaffolder], InvalidOperationException
    + FullyQualifiedErrorId : T4Scaffolding.Cmdlets.SetDefaultScaffolderCmdlet

Set-DefaultScaffolder : Cannot get an instance of EnvDTE.DTE
At C:\dev\WebApplication2\packages\MvcScaffolding.1.0.9\tools\init.ps1:50 char:1
+ Set-DefaultScaffolder -Name UnitTest -Scaffolder MvcScaffolding.ActionUnitTest - ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Set-DefaultScaffolder], InvalidOperationException
    + FullyQualifiedErrorId : T4Scaffolding.Cmdlets.SetDefaultScaffolderCmdlet

Set-DefaultScaffolder : Cannot get an instance of EnvDTE.DTE
At C:\dev\WebApplication2\packages\MvcScaffolding.1.0.9\tools\init.ps1:54 char:1
+ Set-DefaultScaffolder -Name View -Scaffolder $viewScaffolder -SolutionWide -DoNo ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Set-DefaultScaffolder], InvalidOperationException
    + FullyQualifiedErrorId : T4Scaffolding.Cmdlets.SetDefaultScaffolderCmdlet

Answer

Scott Hanselman picture Scott Hanselman · Feb 12, 2014

We are moving to a new system for Scaffolding, but for now, run VS as admin and use this -pre version we've updated:

Install-Package MvcScaffolding -Version 1.0.8-vs2013 -Pre

I'll blog this.