Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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>

enter image description here

like image 794
Twenty Avatar asked Jan 25 '23 20:01

Twenty


1 Answers

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

enter image description here

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.

like image 172
Edward Avatar answered Feb 07 '23 19:02

Edward