I am trying to split up my ASP.NET Core 3.0 pre-release 9 MVC app into different projects. For example, I’d like to have everything related to one subdomain go into a project called Website.SubdomainA
and the other one into Website.SubdomainB
.
I tried to accomplish this with a Razor Class Library. According to MSDN, these should be able to contain the follwing:
Razor views, pages, controllers, page models, Razor components, View components, and data models can be built into a Razor class library (RCL).
So I went ahead and created a 'RCL', which looks something like the following:
<Project Sdk="Microsoft.NET.Sdk.Razor">
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<RazorLangVersion>3.0</RazorLangVersion>
</PropertyGroup>
</Project>
Then I copied over my Controllers and Views—but, for some reason, it can't find any of the assemblies which contain the base classes like Controller
, RouteAttribute
and all the others which are included in the Microsoft.AspNetCore.Mvc
namespace.
Further, my Views do not compile since they can't find the needed assemblies, and things like Layout = "Test"
get marked red.
Am I missing something obvious?
For creating Razor Class Library, you need to append AddRazorSupportForMvc
in the *.csproj
like below:
<Project Sdk="Microsoft.NET.Sdk.Razor">
<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>
<AddRazorSupportForMvc>true</AddRazorSupportForMvc>
</PropertyGroup>
<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>
</Project>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With