如何使用CLI获取Scratold Razor页面?

时间:2017-08-19 01:30:50

标签: razor scaffolding asp.net-core-2.0

tutorial显示了Razor PagesAsp.Net Core 2的实施情况。但是,当我运行CLI命令时:

 dotnet aspnet-codegenerator razorpage -m PatReg -dc ArtCoreDbContext
 -udl -outDir Pages\--referenceScriptLibraries

输出如下所示

enter image description here

我在project.cs中有以下ref-package,

<ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0-preview2-final" />
    <PackageReference Include="Microsoft.AspNetCore.Razor.Tools" Version="1.1.0-preview4-final" />
    <PackageReference Include="Microsoft.Composition" Version="1.0.31" />
    <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.0.0-preview2-final" />
    <PackageReference Include="NETStandard.Library" Version="2.0.0" />
    <PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
    <PackageReference Include="Sendgrid" Version="9.8.0" />
    <PackageReference Include="ASPSMS" Version="0.0.2" />
    <PackageReference Include="System.Composition" Version="1.1.0" />
  </ItemGroup>
  <ItemGroup>
    <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0-preview2-final" />
    <DotNetCliToolReference Include="Microsoft.Extensions.SecretManager.Tools" Version="2.0.0-preview2-final" />
    <DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0-preview2-final" />
  </ItemGroup>

我错过了参考资料吗?

2 个答案:

答案 0 :(得分:3)

确实我错过了一个参考文献。 我更新了所有包并添加了

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

最终.csproj看起来像

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

  <PropertyGroup>
    <TargetFramework>netcoreapp2.0</TargetFramework>
    <MvcRazorCompileOnPublish>true</MvcRazorCompileOnPublish>
    <UserSecretsId>--------------------------</UserSecretsId>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
    <PackageReference Include="Microsoft.Composition" Version="1.0.31" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0" />
    <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.0.0" />
    <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0" />
    <PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
  </ItemGroup>
  <ItemGroup>
    <DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="1.0.1" />
  </ItemGroup>
  <ItemGroup>
    <DotNetCliToolReference Include="Microsoft.Extensions.SecretManager.Tools" Version="2.0.0-preview2-final" />
  </ItemGroup>

</Project>

答案 1 :(得分:2)

在项目文件夹中,运行以下两个命令。

dotnet add package Microsoft.VisualStudio.Web.CodeGeneration.Design

dotnet build

参考:https://gavilan.blog/2018/04/28/asp-net-core-2-doing-scaffolding-with-dotnet-cli-aspnet-codegenerator/