在 VS 2017 中使用脚手架时出错 [英] Error using scaffolding in VS 2017

查看:29
本文介绍了在 VS 2017 中使用脚手架时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 Visual Studio 2017 的 ASP.NET Core 应用程序中使用 Scaffold 功能.我正在使用带有视图的 MVC 控制器,使用实体框架.我已经设置了 dbcontext 和迁移,并使用 update-database 创建了一个数据库.我选择了最小"脚手架选项.选择模型和 dbcontext 后,当我单击确定"时,我收到一个状态对话框,说它是脚手架,但该对话框退出并显示错误:

I am attempting to use the Scaffold feature in an ASP.NET Core application in Visual Studio 2017. I'm using the MVC Controller with views, using Entity Framework. I've set up a dbcontext and migration and used update-database to create a database. I chose the "Minimal" scaffold option. After choosing the model and dbcontext, when I click OK, I get a status dialog saying it is scaffolding, but that dialog exits with the error:

错误 运行所选代码生成器时出错:'未处理的异常:System.IO.FileNotFoundException:无法加载文件或程序集 'Microsoft.VisualStudio.Web.CodeGeneration.Utils,版本=1.1.0.0,文化=中性,PublicKeyToken=adb9793829ddae60'.该系统找不到指定的文件.在Microsoft.VisualStudio.Web.CodeGeneration.Design.Program.Main(String[]args)'

Error There was an error running the selected code generator: 'Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.VisualStudio.Web.CodeGeneration.Utils, Version=1.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified. at Microsoft.VisualStudio.Web.CodeGeneration.Design.Program.Main(String[] args)'

我已确保 Microsoft.VisualStudio.Web.CodeGeneration.Utils 和 Microsoft.VisualStudio.Web.CodeGeneration.Design 在我的项目中作为包引用,尽管我不清楚这是否适合它们.这是一个新的 Azure VM,预装了 VS2017 社区,最新更新,没有 3rd 方加载项等.这个错误也会发生在空视图脚手架上,所以我很确定与 EF 无关.

I have made sure both Microsoft.VisualStudio.Web.CodeGeneration.Utils and Microsoft.VisualStudio.Web.CodeGeneration.Design are referenced as packages in my project, though I'm not clear that is the right place for them. This is a new Azure VM with VS2017 Community pre-installed, latest updates, and no 3rd party add-ins, etc. This error also occurrs scaffolding an empty view, so I'm fairly certain has nothing to do with EF.

如何解决此问题以使脚手架功能正常工作?

How can I resolve this to get the scaffolding feature working?

推荐答案

无法加载 Microsoft.VisualStudio.Web.CodeGeneration.Utils 程序集的错误通常是由于 NuGet 包缓存或由于包的版本不匹配导致的项目.

The error about not being able to load Microsoft.VisualStudio.Web.CodeGeneration.Utils assembly is usually due to NuGet package cache or due to version mismatches of packages in the project.

你能展示你的 .csproj 文件吗?

Can you show your .csproj file?

尝试一些事情:

  1. 确保脚手架包 Microsoft.VisualStudio.Web.CodeGeneration.Design 的包引用具有正确的版本:一种.1.0.x 用于 ASP.NET Core 1.0 等.

  1. Ensure the package reference for the scaffolding packages Microsoft.VisualStudio.Web.CodeGeneration.Design has the right version: a. 1.0.x for ASP.NET Core 1.0 and such.

其他不应直接引用的脚手架包是一种.Microsoft.VisualStudio.Web.CodeGeneration.Utils湾Microsoft.VisualStudio.Web.CodeGeneration.TemplatingC.Microsoft.VisualStudio.Web.CodeGeneration.EntityFrameworkCored.Microsoft.VisualStudio.Web.CodeGeneration.Coree.Microsoft.VisualStudio.Web.CodeGenerationF.Microsoft.VisualStudio.Web.CodeGeneration.MsBuildG.Microsoft.VisualStudio.Web.CodeGeneration.ContractsH.Microsoft.VisualStudio.Web.CodeGenerators.Mvc一世.Microsoft.VisualStudio.Web.CodeGeneration.Tools -- 这个必须是一个 DotNetCliToolReference

Other scaffolding packages that shouldn’t be referenced directly are a. Microsoft.VisualStudio.Web.CodeGeneration.Utils b. Microsoft.VisualStudio.Web.CodeGeneration.Templating c. Microsoft.VisualStudio.Web.CodeGeneration.EntityFrameworkCore d. Microsoft.VisualStudio.Web.CodeGeneration.Core e. Microsoft.VisualStudio.Web.CodeGeneration f. Microsoft.VisualStudio.Web.CodeGeneration.MsBuild g. Microsoft.VisualStudio.Web.CodeGeneration.Contracts h. Microsoft.VisualStudio.Web.CodeGenerators.Mvc i. Microsoft.VisualStudio.Web.CodeGeneration.Tools -- This one needs to be a DotNetCliToolReference

清除本地 NuGet 缓存.

Clear the local NuGet cache.

这篇关于在 VS 2017 中使用脚手架时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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