该问题似乎是由 MvcScaffolder 包的安装/注册不完整引起的。
以下过程为我解决了我的问题。
启动 Visual Studio 并打开项目。 打开包管理器控制台。 (这是导致解决方案的“技巧”或缺失的信息...)
这里我看到了用于注册的 PowerShell 脚本导致的以下错误:
New-Object : Could not load file or assembly 'System.Management.Automation, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
At <ProjectPath...>\packages\MvcScaffolding.1.0.9\tools\registerWithMvcTooling.ps1:163 char:27
+ $newProvider = New-Object <<<< $powerShellScaffolderProviderType($mvcScaffoldingProvider)
+ CategoryInfo : NotSpecified: (:) [New-Object], FileNotFoundException
+ FullyQualifiedErrorId : System.IO.FileNotFoundException, Microsoft.PowerShell.Commands.NewObjectCommand
当我从包管理器控制台检查注册的脚手架时,我得到:
PM> get-defaultscaffolder
DefaultName ScaffolderName
Action MvcScaffolding.Action
Controller MvcScaffolding.Controller
CustomScaffolder T4Scaffolding.CustomScaffolder
CustomTemplate T4Scaffolding.CustomTemplate
DbContext T4Scaffolding.EFDbContext
Mailer Mailer.Razor
Repository T4Scaffolding.EFRepository
UnitTest MvcScaffolding.ActionUnitTest
View MvcScaffolding.RazorView
Views MvcScaffolding.Views
很明显,脚手架配置为使用 MvcScaffolding 包,但该包有注册错误。
快速搜索错误提供了此链接http://mvcscaffolding.codeplex.com/discussions/437692,它指的是https://visioautomation.codeplex.com/discussions/397034,它建议安装PowerShell 3,它实际上是Windows Management Framework 3.0 的一部分,可从http://www.microsoft.com/en-us/download/details.aspx?id=34595 获得。我在提示时选择了 Windows6.1-KB2506143-x64.msu 文件,因为我运行的是 Win 7-64 位。
安装后重启电脑,重新打开Visual Studio和项目,查看Package Manager Console。如果错误消失了,那么控制器问题也消失了。