The name "model" does not exist in the current context in ASP.NET Core
I am trying to create a plugin website using ASP.NET Core. I have my main project, an asp.net web application that works great. I have a class library project with controllers that also works fine and the views I'm having problem with. When I open the * .cshtml file I see that Razor is not working - @using, @model and other directives are not recognized and intellisense is not working. When I wind up on the model, I am given an error from the header:
The name "model" does not exist in the current context in ASP.NET Core
I am using EmbeddedFileProvider to detect views and they are marked as embedded resource. When I run the application everything works - the views are displayed correctly. My only problem is false positive errors in Visual Studio. I googled and there similar issues, but mostly for ASP.NET MVC and not Core - like here . I think there is something missing in the configuration of the class library, but I'm not sure what exactly.
source to share
The new csproj file has an Sdk attribute on the top-level Project element. When you create a new web application, it is installed in the "Web" SDK:
<Project Sdk="Microsoft.NET.Sdk.Web">...</Project>
When you add / create a class library, the default non-web SDK is used:
<Project Sdk="Microsoft.NET.Sdk">...</Project>
As far as I can tell, the web SDK imports additional tasks to handle design-time web resources such as Razor views. Change the SDK in your plugin library to website.
Another setting for the Web project is that it outputs the EXE by default, so add this to your csproj plugin as well:
<PropertyGroup>
<OutputType>Library</OutputType>
</PropertyGroup>
source to share