8

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?

6
  • I guess you are missing <PackageReference Include="Microsoft.AspNetCore.Mvc" Version="{version}" /> in your project file. Or other reference needed. Commented Sep 7, 2019 at 21:38
  • @dropoutcoder Well yes, but I want the latest pre-release, see this. And if I add what the link shows I get the following error: The FrameworkReference 'Microsoft.AspNetCore.App' was not recognized. Commented Sep 7, 2019 at 21:39
  • Did you tried to just install the preview package(s) from NuGet to those projects? Commented Sep 7, 2019 at 21:47
  • I am over-viewing the links and I am not sure that Framework element is yet working in the preview. It might not yet. That is why you have that error. Commented Sep 7, 2019 at 21:48
  • Well the latest Microsoft.AspNetCore.Mvc package is version 2.2 and not some kind of pre-release Commented Sep 7, 2019 at 21:48

2 Answers 2

10

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>
Sign up to request clarification or add additional context in comments.

Comments

1

Try using <TargetFramework>netcoreapp3.0</TargetFramework>. See this comment in the issue you linked to above.

We are removing the netstandard2.0 from most Microsoft.AspNetCore.* assemblies.

10 Comments

I already tried that, but if I do this I get the following errors you can see in this picture.
@Twenty Ok I see. Can you clear your "obj" folder contents (that will get rid of all those "*.cshtml.g.cs" errors) and see what the remaining errors are?
I cleared the bin as well as the obj folder, if I hit build, I still hit the exact same issues.
What happens if you target the web SDK instead of the Razor SDK? <Project Sdk="Microsoft.NET.Sdk.Web">
Well I need the Razor SDK, that is the problem... and no the errors disappear.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.