简体   繁体   中英

Creating Razor Class Library with TargetFramework to .net core 3 throws errors

I am creating an ASP.Net Core 3 pre-release 9 MVC app and I want to create some Razor Class Libraries (RCL). When creating a RCL from the template it will default to targeting netstandard2.0 which is indeed not possible for .Net Core 3 anymore referring to the following GitHub issue . This then throws some weird errors by the following code:

<Project Sdk="Microsoft.NET.Sdk.Razor">
  <PropertyGroup>
    <TargetFramework>netcoreapp3.0</TargetFramework>
    <RazorLangVersion>3.0</RazorLangVersion>
  </PropertyGroup>

  <ItemGroup>
    <FrameworkReference Include="Microsoft.AspNetCore.App" />
  </ItemGroup>
</Project>

在此处输入图片说明

For creating RCL for MVC, you need to configuring Support pages and views like

在此处输入图片说明

For this, it will append <AddRazorSupportForMvc>true</AddRazorSupportForMvc> in your *.csproj like

<Project Sdk="Microsoft.NET.Sdk.Razor">
<PropertyGroup>
    <TargetFramework>netcoreapp3.0</TargetFramework>
    <AddRazorSupportForMvc>true</AddRazorSupportForMvc>
</PropertyGroup>
<ItemGroup>
    <FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>
</Project>

For above screen shot, it uses VS 2019 Preview.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM