问题描述
我已经创建了一个针对net461的.Net Core MVC6应用程序.我使用了一个非常熟悉的项目结构,在其中将数据,模型和服务类放置在单独的类库项目中,而Web项目引用了它们.
I have created an .Net Core MVC6 application targeting net461. I have used a project structure I am very familiar with in which I place the data, model, and service classes in separate class library projects and the Web project references these.
当我尝试搭建一个控制器时,我收到一个错误,指出我正在搭建的模型存在多种匹配类型.
When I attempt to scaffold a controller I receive an error that multiple matching types exist for the model I am scaffolding.
如果我将所有代码移至单个项目,则脚手架成功.如果将上下文移至Web项目并将模型留在单独的项目中,则会收到错误消息,找不到匹配的类型.
If I move all code to a single project, scaffolding is successful. If I move the context to Web project and leave the model in a separate project, I receive an error the NO matching types were found.
还有其他人看到过同样的问题吗?是否有解决方法仍可以使用这种类型的体系结构?
Has anyone else seen this same issue? Is there a workaround to still use this type of architecture?
更新
我开始了另一个项目,总是遇到这个问题.仅对模型使用1个额外项目时出现此错误.附件是我收到的错误.
I started another project and always get this issue. I get this error when only using 1 extra project for the models. Attached is the error I recieve.
更新2
当上下文和模型在同一项目中时,我会收到此错误.
When the context and model are in the same project I receive this error.
推荐答案
无法发表评论,所以我不得不写一个答案.我也遇到了同样的问题,并在Scaffolding github存储库上将其打开.这是响应:
Cannot post a comment, so I've to write an answer instead. I also had the same issue and opened it on Scaffolding github repository. Here's the response:
作为一种解决方法,您可以将模型临时添加到Web项目中 然后在脚手架上将其移至BLL/DAL项目.
As a workaround, you can add the model temporarily to your web project and then move it to the BLL/ DAL projects after scaffolding.
此外,他们还打开了此问题作为错误,并引用:
Plus they also opened this issue as a bug, quoting:
项目A依赖于项目B.项目B具有模型类If 您尝试通过使用以下模型类在Project A上运行脚手架 项目B,它失败,并出现以下错误:没有返回任何模型类型 类型:
Project A has a dependeny on Project B. Project B has model class If you try to run scaffolding on Project A by using model class from Project B, it fails with the below error: No model type returned for type:
因此,从RC2开始,这是脚手架工具中的错误.
Hence, as of RC2, this is a bug in scaffolding tooling.
这篇关于.Net Core中的支架与解决方案中的多个项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!