Mvc5,EF6,VisualStudio 2013中带有存储库的脚手架控制器

时间:2013-09-29 17:25:15

标签: visual-studio-2013 asp.net-mvc-scaffolding entity-framework-6 asp.net-mvc-5 t4scaffolding

在vs2012中,我曾经使用过史蒂夫·桑德森的mvcScaffolding Package这个包,我可以使用单元测试和带有存储库和依赖注入的控制器来构建Action Methods。 我的问题很简单。在vs2013中有没有办法这样做? 当我在vs2013中安装软件包时,出现以下错误:

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

5 个答案:

答案 0 :(得分:9)

我们正在转向新的Scaffolding系统,但是现在,以管理员身份运行VS并使用我们已更新的-pre版本:

Install-Package MvcScaffolding -Version 1.0.8-vs2013 -Pre

我会写博客。

答案 1 :(得分:2)

您得到的错误是它无法创建VS IDE(EnvDTE.DTE)的实例。该脚手架包引用了旧版本的VS IDE,因此在VS2013中无法使用。该项目必须更新才能正确支持VS2013。

Codeplex项目看起来好像很久没有更新了,所以我的猜测是,除非项目移动到不同的开源存储库,否则它已经死了。

由于ASP.NET现在内置了自己的脚手架,我建议现在是时候转换了。

答案 2 :(得分:2)

在命令行中尝试: cd C:\ Program Files(x86)\ Microsoft Visual Studio 12.0 \ Common7 \ IDE \ devenv.exe / setup" Extensions \ Microsoft \ Web \ Mvc \ Scaffolding \ Microsoft.AspNet.Scaffolding.Mvc.5.0.dll"

答案 3 :(得分:1)

为了解决VS2013 Update 4上的这个问题,我将不得不从所有模块上卸载。\ packages directorie删除所有T4 *,从VS退出。

再次输入,并使用来自witttness的解决方案,在包管理器控制台上执行: 安装包MvcMailer-vs2013 -pre和voilá,从那时起它的工作......

感谢您的一切

答案 4 :(得分:1)

我知道这是在不久前发布的,但是,我在使用MvcScaffolding时在VS2015中遇到了同样的错误。实际的错误在于T4Scaffolding.Core包。我删除了源代码,修复了错误,并上传了带有链接依赖项的新NuGet包。 3个新包装是:

首先卸载MvcScaffolding及其依赖项,T4Scaffolding,& T4Scaffolding.Core。如果您只是安装MvcScaffolding包,其他包将被拉过来。希望这有助于其他人。

干杯。