0

I have an asp.net core mvc project compiled as a dll:

<OutputType>Library</OutputType>

This project is referenced from a Windows Service project (classic .NET) and hosted inside it. This works well while I don't have views. The problem I have is when I add views which it tries to compile at runtime not finding the references.

What I thought is that, maybe, precompiling the views would fix the issue. But I can't seem to find the way to precompile the views for a "Library" output project.

Is there a way to precompile views for a Library type project in ASP.NET *core?

Update: Some more information. It seems that the targets to precompile the views only work with Exe outputs because they expect to have a .exe and .exe.config files generated; this does not happen for a "Library" project (as it only generates a .dll file) and the building of the .PrecompiledViews.dll fails.

Carles Company
  • 7,118
  • 5
  • 49
  • 75

1 Answers1

0

There are as named View components in ASP.NET Core. So yes, you can create library with your view components and share them between your UI projects. Check this post for the details - Loading View Components from a Class Library in ASP.NET Core MVC

New to ASP.NET Core MVC, view components are similar to partial views, but they're much more powerful. View components don't use model binding, and only depend on the data provided when calling into it. A view component:

  • Renders a chunk rather than a whole response.
  • Includes the same separation-of-concerns and testability benefits found between a controller and view.
  • Can have parameters and business logic.
  • Is typically invoked from a layout page.
Dmitry Pavlov
  • 30,789
  • 8
  • 97
  • 121
  • I think I have not explained my issue very well... :) The problem I have is that I need to have my asp.net core project deploying a dll but at the same time precompiling the views. View precompilation only works for me with an "Exe" type output. – Carles Company Mar 08 '18 at 12:09
  • Did you have a chance to check this? http://www.iaspnetcore.com/Blog/BlogPost/593df8ea84cd453ecc6d8a26/aspnet-core-precompiling-razor-views – Dmitry Pavlov Mar 08 '18 at 12:18