aspnet core codegenerator fails to create scaffolded controller

一曲冷凌霜 提交于 2019-12-24 01:56:19

问题


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)

It would be helpful to know which type wasn't being returned.

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?


回答1:


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.

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

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

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.



来源:https://stackoverflow.com/questions/40396384/aspnet-core-codegenerator-fails-to-create-scaffolded-controller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!