aspnet核心代码生成器无法创建脚手架控制器

时间:2016-11-03 07:57:35

标签: asp.net-mvc scaffolding .net-core

我有一个aspnet核心v1.0.1应用程序,我已将模型/迁移提取到一个单独的程序集中。我添加了一个新模型,但是当我尝试使用scaffold创建一个控制器时,我得到了这个错误:

Finding the generator 'controller'...
Running the generator 'controller'...
Attempting to compile the application in memory
There was an error creating/modifying a DbContext, there was no type returned after compiling the new assembly successfully
   at Microsoft.VisualStudio.Web.CodeGeneration.ActionInvoker.<BuildCommandLine>b__6_0()
   at Microsoft.Extensions.CommandLineUtils.CommandLineApplication.Execute(String[] args)
   at Microsoft.VisualStudio.Web.CodeGeneration.CodeGenCommand.Execute(String[] args)

知道哪种类型没有被退回会很有帮助。

dotnet命令是:

"C:\Program Files\dotnet\dotnet.exe" aspnet-codegenerator --project "C:\Projects\CompetitionScores\src\CSWebSite" controller --force --controllerName ClubsController --model CompetitionScores.Data.Models.Club --dataContext CompetitionScores.Data.CompetitionScoresDbContext --relativeFolderPath Controllers --controllerNamespace CSWebSite.Controllers --referenceScriptLibraries --useDefaultLayout

我有什么想法可以解决这个问题吗?

1 个答案:

答案 0 :(得分:1)

当模型位于当前项目之外时,听起来目前脚手架存在一些问题。作为解决方法,您可以将模型临时添加到Web项目中,然后在脚手架后将其移动到BLL / DAL项目。

我的团队在进行此类设置时出现的问题示例(不完全是您遇到的问题,但我认为我们的设置足够相似,问题可能是同一问题): https://github.com/aspnet/Scaffolding/issues/249

最近修复此问题的提交(表示已批准版本1.0.0-preview2-update1): https://github.com/aspnet/Scaffolding/commit/b12a8068eb6312e108f2abdfa6f837b142025c0e

所以我想直到1.0.0-preview2-update1,只要你有一个项目将事物分成多个程序集,这仍然是一个问题。在我的情况下,项目设置太复杂,无法将事物复制到一个项目中......所以我只能把头撞到墙上:(并开始键入脚手架代码。

相关问题