本文介绍了添加剃刀视图时的VS2017 ASP .NET Core错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我右键单击一个文件夹时,Add-> View添加一个Razor View:

When I right click on a folder Add->View to add a Razor View:

我收到以下错误:

No executable found matching the command dotnet-aspnet-codegenerator

从在线初步搜索中,我没有找到解决方案.我已经在某些项目上进行了这项工作-但无法弄清楚如何解决这个问题!我已经重新安装了VS2017,但问题仍然存在.

From initial searches online, I've not found a solution. I've had this working on some projects - but cannot figure how to resolve this! I've reinstalled VS2017 but the problem still exists.

我怀疑这是项目中的内容.我尝试读取与代码生成相关的软件包,但问题仍然存在.

I suspect it is something in the project. I've tried readding the code generation related packages but still the problem exists.

这是我的csproj软件包和工具参考:

Here is my csproj Package and Tool references:

<Project Sdk="Microsoft.NET.Sdk.Web">

    <PropertyGroup>
        <TargetFramework>net462</TargetFramework>
        <RuntimeIdentifier>win7-x86</RuntimeIdentifier>
    </PropertyGroup>

    <ItemGroup>
        <PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.0.0" />
        <PackageReference Include="Microsoft.AspNetCore" Version="1.1.1" />
        <PackageReference Include="Microsoft.AspNetCore.Authentication.Cookies" Version="1.1.1" />
        <PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="1.1.1" />
        <PackageReference Include="Microsoft.AspNetCore.Identity" Version="1.1.1" />
        <PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="1.1.1" />
        <PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.2" />
        <PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="1.1.1" />
        <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="1.1.1" PrivateAssets="All" />
        <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="1.1.1" />
        <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer.Design" Version="1.1.1" PrivateAssets="All" />
        <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="1.1.0" />
        <PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="1.1.1" />
        <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.1" />
        <PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink" Version="1.1.0" />
        <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="1.1.0" PrivateAssets="All" />
        <PackageReference Include="SimpleInjector.Integration.AspNetCore.Mvc" Version="3.3.2" />
        <PackageReference Include="Telerik.UI.for.AspNet.Core" Version="2017.1.223" />
    </ItemGroup>
    <ItemGroup>
        <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="1.0.0" />
        <DotNetCliToolReference Include="Microsoft.Extensions.SecretManager.Tools" Version="1.0.0" />
        <DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="1.0.0" />
    </ItemGroup>

我也存在使用右键单击Add-> Controller添加Controllers的相同问题,因此这不仅限于Razor Views.

I have the same issue adding Controllers using right-click Add->Controller too, so this is not restricted to Razor Views.

这可以从上下文菜单添加"->新建项..."->"MVC视图"页面或添加->新建项...-> MVC控制器类"中起作用.

This does work from context menu Add->New Item...->MVC View Page or Add->New Item...->MVC Controller Class.

推荐答案

今晚我又发生了完全相同的事情.

I had the exact same thing happen again tonight.

我在几乎空的ASP NET Core应用程序中添加了Razor View.系统提示我选择一个向项目添加最小依赖项或完全依赖项的选项.

I added a Razor View to my pretty much empty ASP NET Core Application. I was prompted to select an option to add minimal dependencies or full dependencies to the project.

我选择了最小的依赖关系,然后出现了ScaffoldingReadMe.txt.内容为:

I opted for minimal dependencies then a ScaffoldingReadMe.txt appeared. It read:

ASP.NET MVC核心依赖项已添加到项目中.但是,您可能仍需要对项目进行更改.

ASP.NET MVC core dependencies have been added to the project.However you may still need to do make changes to your project.

1. Add Scaffolding CLI tool to the project:

<ItemGroup>
    <DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="1.0.1" />
</ItemGroup>

我尝试通过脚手架添加视图,但是像以前一样失败了.但是,将文本文件中的内容接受后,将上述XML添加到csproj文件中就可以了-该视图已成功搭建好脚手架.

I tried adding the view via scaffolding and it failed as before. However, taking on board what the text file said, adding the above XML to the csproj file worked - the view was scaffolded successfully.

这篇关于添加剃刀视图时的VS2017 ASP .NET Core错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-06 14:17