Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating an Razor Class Library with Framework Reference to Microsoft.AspNetCore.App #13801

Closed
TwentyFourMinutes opened this issue Sep 7, 2019 · 4 comments
Labels
area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates

Comments

@TwentyFourMinutes
Copy link

Describe the bug

I am trying to put some of my Controllers and Views of my ASP.Net Core 3 pre-release 9 MVC Project in a different Project. Therefor I went with an Razor Class Library since as the documentation says:

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 Project which looks something like the following:

<Project Sdk="Microsoft.NET.Sdk.Razor">
  <PropertyGroup>
    <TargetFramework>netstandard2.1</TargetFramework>
    <RazorLangVersion>3.0</RazorLangVersion>
  </PropertyGroup>

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

I included the FrameworkReference instead of a PackageReference for the Microsoft.AspNetCore.App since the following issue tells me so. #3756

But this leaves me with the following error:

The FrameworkReference 'Microsoft.AspNetCore.App' was not recognized

@pranavkm
Copy link
Contributor

pranavkm commented Sep 7, 2019

You'll need a TargetFramework of netcoreapp3.0. Does changing the tfm fix the issue?

@pranavkm pranavkm added the area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates label Sep 7, 2019
@TwentyFourMinutes
Copy link
Author

TwentyFourMinutes commented Sep 8, 2019

Well if I use netcoreapp3.0 it resolves the dependency issues, but other errors occur.

image

I am not sure what the reason for this is...

@TwentyFourMinutes
Copy link
Author

Also if it is the case that netcoreapp3.0 is the only possible TargetFramework, the template for RazorClassLibraries should be updated. They currently use netstandard2.0.

@TwentyFourMinutes
Copy link
Author

For anyone else interested and having the same issue, you need to add this attribute <AddRazorSupportForMvc>true</AddRazorSupportForMvc> to your .csproj of the RCL.

@ghost ghost locked as resolved and limited conversation to collaborators Dec 2, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-mvc Includes: MVC, Actions and Controllers, Localization, CORS, most templates
Projects
None yet
Development

No branches or pull requests

2 participants