添加新视图时运行选定的代码生成器时出错 [英] there was an error running the selected code generator when adding new view

查看:114
本文介绍了添加新视图时运行选定的代码生成器时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究一个asp.net核心MVC项目.我需要为控制器的方法添加视图.为此,我右键单击所考虑方法的主体,然后选择添加视图",但系统显示一个错误:

I'm working on a asp.net core MVC project. I need to add a view for a method of a controller. To do that, I right click on the body of the considered method and then choose Add View but the system shows me an error:

运行所选代码生成器时出错:程序包还原失败,无法回滚程序包更改MyProject.

there was an error running the selected code generator: Package restore failed rolling back package changes MyProject.

如果有人告诉我如何解决此问题,我将不胜感激.

I appreciate if anyone tells me how I can fix the issue.

推荐答案

我已经为此打了一段时间.我按照以下步骤解决了这个问题.

I've been banging my head for a while with this. I resolved it by following these steps.

  1. 确保所有软件包都是完全相同的版本!甚至补丁版本似乎都失败了.因此,如果您的SQLite是3.1.1,而SQLServer是3.1.2,它将失败

  1. Make sure all Packages are exactly the same version! Even Patch versions seem to fail. So if your SQLite is 3.1.1 and you SQLServer is 3.1.2 it will fail

打开您的 csproj 文件,然后手动将软件包的版本编辑为完全相同的版本.目前它的版本为5.0.3,但我在 5.0.2 上有 Microsoft.VisualStudio.Web.CodeGeneration.Design ,但失败了

Open your csproj file and manually edit the versions of the packages to the exact same version. Currently its 5.0.3 for everything but I had Microsoft.VisualStudio.Web.CodeGeneration.Design at 5.0.2 and it was failing

  1. 可选步骤:从所有项目中删除这些程序包

<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="5.0.2" />
        <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.2" />
        <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration" Version="5.0.2" />
        <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="5.0.2" />
        

  1. 手动编辑 csproj 文件后,对其进行保存(对所有 csproj 文件进行更改)

  1. After you manually edit the csproj file, save it/them (make changes in all your csproj files btw)

我也执行了此步骤- Nuget Package Manager设置-> Package Sources 取消选择本地文件夹,仅确保选择了远程文件夹

I also did this step - Nuget Package Manager Settings -> Package Sources Unselect the local folder and only make sure the remote one is selected

  1. 关闭Visual Studio 2019.

  1. Close Visual Studio 2019.

删除解决方案文件夹中的 .vs 文件夹.

Delete .vs folder in the Solution folder.

再次启动Visual Studio,设置启动项目等.

Start Visual Studio again, set startup project etc.

现在尝试创建一个脚手架控制器,它将再次安装软件包并且可以正常工作!

Now try creating a scaffolder controller, it will install the packages again and should work!

这篇关于添加新视图时运行选定的代码生成器时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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