aspnet核心代码生成器无法创建脚手架控制器 [英] aspnet core codegenerator fails to create scaffolded controller

查看:106
本文介绍了aspnet核心代码生成器无法创建脚手架控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个aspnet core v1.0.1应用程序,并且已将模型/迁移提取到单独的程序集中。我添加了一个新模型,但是当我尝试使用脚手架创建控制器时,出现此错误:

I have an aspnet core v1.0.1 application and I have extracted the models/migrations into a separate assembly. I have added a new model, but when I try to create a controller with scaffold I get this error:

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命令是:

The dotnet command is:

"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

有什么想法可以解决此问题吗?

Any ideas how I can fix this?

推荐答案

当模型位于当前项目之外时,脚手架当前存在一些问题。解决方法是,您可以暂时将模型添加到Web项目中,然后在脚手架上将其移至BLL / DAL项目中。

It sounds like there are currently some issues with scaffolding when the models are located outside the current project. As a workaround, you can add the model temporarily to your web project and then move it to the BLL/DAL projects after scaffolding.

我的团队遇到的问题示例此类设置(不完全是您遇到的设置,但我认为我们的设置足够相似,并且问题可能是由于同一问题所致):
> https://github.com/aspnet/Scaffolding/issues/249

Example of issue my team were having with this sort of setup (not exactly what you're coming across, but I think our setups are similar enough and the problem might be due to the same issue): https://github.com/aspnet/Scaffolding/issues/249

最近解决此问题的承诺(表示已批准使用1.0.0-preview2-update1版本):
https://github.com/aspnet/Scaffolding/commit/b12a8068eb6312e108f2abdfa6f837b142025c0e

A recent commit to fix this issue (indicates approved for version 1.0.0-preview2-update1): https://github.com/aspnet/Scaffolding/commit/b12a8068eb6312e108f2abdfa6f837b142025c0e

所以我想直到1.0.0-preview2-update1,只要您有一个将项目分解为多个程序集的项目,这仍然是一个问题。就我而言,项目设置太复杂了,无法将东西复制到一个项目中……所以我只能将头撞在墙上:(然后开始输入脚手架代码。

So I suppose up until 1.0.0-preview2-update1, this will remain an issue so long as you have a project that splits things out into more than one assembly. In my case, the project setup is too complicated to copy things into one project... So I can only bang my head against the wall :( and start typing the scaffolded code.

这篇关于aspnet核心代码生成器无法创建脚手架控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆