Home > front end >  Which packages to reference in Microsoft.NET.Sdk.Razor project to get full ASP.NET Core
Which packages to reference in Microsoft.NET.Sdk.Razor project to get full ASP.NET Core

Time:12-20

I want to create a modular Web application using ASP.NET Core.

So my structure is to have a full ASP.NET Core application project

<Project Sdk="Microsoft.NET.Sdk.Web">

and multiple projects of type

<Project Sdk="Microsoft.NET.Sdk.Razor">

The reason for using Microsoft.NET.Sdk.Razor is that it doesn't require a Program.cs with a static Main method.

However, when I try to reference e.g. IViewLocationExpander it is not available due to the lack of some assembly references.

My problem now is which version of the overwhelming list of Microsoft.AspNetCore.* packages to pick in which version (for .NET 6 I expect to be something like 6.0.12).

IViewLocationExpander is part of Microsoft.AspNetCore.Mvc.Razor in assembly Microsoft.AspNetCore.Mvc.Razor (Microsoft.AspNetCore.Mvc.Razor.dll`).

But Microsoft.AspNetCore.Mvc.Razor is only available until version 2.2.0 so it seems to be outdated.

How do I solve this?

CodePudding user response:

Using <FrameworkReference Include="Microsoft.AspNetCore.App" /> in your project file should do the trick - it avoids a lot of the headaches with working out which packages to reference and gets you all the Razor ones (and all the other useful ASP.NET Core bits) out of the box.

As mentioned by @Alexander in the comments the docs for this are here: https://learn.microsoft.com/en-us/aspnet/core/fundamentals/target-aspnetcore?view=aspnetcore-6.0

  • Related