RazorLight: Cannot find compilation library location for package 'Microsoft.NETCore.App'

Describe the bug My code run ok on developer machine. But not in Azure WebApp production.

Im using .Net Core 2.1. I get this error

Cannot find compilation library location for package 'Microsoft.NETCore.App'

To Reproduce Steps to reproduce the behavior:

string html = await _engine.CompileRenderAsync(templateKey, razor, data);

Expected behavior A clear and concise description of what you expected to happen.

Information (please complete the following information):

  • OS: Windows Server 2016 (Azure WebApp) Plataform: .NET Core 2.1
  • RazorLight version : e.g 2.0-beta1

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 14
  • Comments: 17

Commits related to this issue

Most upvoted comments

I solve the problem, putting this on csproj

  <PropertyGroup>
    <TargetFramework>netcoreapp2.1</TargetFramework>
   <PreserveCompilationContext>true</PreserveCompilationContext>
   <MvcRazorExcludeRefAssembliesFromPublish>false</MvcRazorExcludeRefAssembliesFromPublish>
  </PropertyGroup>

The key is the “MvcRazorExcludeRefAssembliesFromPublish” tag

The main problem in using Library for storing the Embedded Views. Here is an explanation: https://github.com/aspnet/Mvc/issues/6021

So I had to clean up the library csproj file from any additional configuration and add <MvcRazorExcludeRefAssembliesFromPublish>false</MvcRazorExcludeRefAssembliesFromPublish> to the WebApp itself.

Here’s a very useful solution to this problem.

When publishing, view the Settings. Select ‘File Publish Options’ -> Remove additional files at destination.

There’s an outdated assembly that’s causing problems, and this should clear it for you.

Hey everybody,

I ran into the same issue. Unfortunately I was not able to find the solution helped me. I have tried this one: https://github.com/toddams/RazorLight/issues/203#issuecomment-403503671 I have also tried this one: https://stackoverflow.com/questions/51269559/razor-templates-cannot-find-compilation-library-location-for-package

@OblivionSY your sample (https://github.com/toddams/RazorLight/issues/203#issuecomment-422851064) has the latest line commented which is original one from the @penihel response (https://github.com/toddams/RazorLight/issues/203#issuecomment-403503671). So I’m a bit confusing.

I’m using dotnetcore2.1. I have the Email service library with the templates inside as an Embedded resources + main WebApp with the regular .cshtml pages. So I have added the referenced sections to the library project. I have tried Azure DevOps Build\Release process as well as publishing from VS2017 manually. No luck. I have also tried to remove the wwwroot folder from the Azure WebApp using the Kudo tool to force the truly clear publish.

I ended up with all 3 parameters:

    <PreserveCompilationContext>true</PreserveCompilationContext>
    <MvcRazorCompileOnPublish>false</MvcRazorCompileOnPublish>
    <MvcRazorExcludeRefAssembliesFromPublish>false</MvcRazorExcludeRefAssembliesFromPublish>

Here is the stack trace from Azure:

[13:44:54.396 ERR] [ExceptionHandlerMiddleware] An unhandled exception has occurred while executing the request.
System.InvalidOperationException: Cannot find compilation library location for package 'Microsoft.NETCore.App'
   at Microsoft.Extensions.DependencyModel.CompilationLibrary.ResolveReferencePaths(ICompilationAssemblyResolver resolver, List`1 assemblies)
   at Microsoft.Extensions.DependencyModel.CompilationLibrary.ResolveReferencePaths()
   at RazorLight.Compilation.DefaultMetadataReferenceManager.<>c.<Resolve>b__3_0(CompilationLibrary library)
   at System.Linq.Enumerable.SelectManySingleSelectorIterator`2.MoveNext()
   at RazorLight.Compilation.DefaultMetadataReferenceManager.Resolve(Assembly assembly)
   at RazorLight.Compilation.RoslynCompilationService.EnsureOptions()
   at RazorLight.Compilation.RoslynCompilationService.get_ParseOptions()
   at RazorLight.Compilation.RoslynCompilationService.CreateCompilation(String compilationContent, String assemblyName)
   at RazorLight.Compilation.RoslynCompilationService.CompileAndEmit(GeneratedRazorTemplate razorTemplate)
   at RazorLight.TemplateFactoryProvider.CreateFactory(GeneratedRazorTemplate razorTemplate)
   at RazorLight.TemplateFactoryProvider.CreateFactoryAsync(String templateKey)
   at RazorLight.RazorLightEngine.CompileTemplateAsync(String key)
   at RazorLight.RazorLightEngine.CompileRenderAsync(String key, Object model, Type modelType, ExpandoObject viewBag)
   at FluentEmail.Razor.RazorRenderer.ParseAsync[T](String template, T model, Boolean isHtml)
   at FluentEmail.Razor.RazorRenderer.FluentEmail.Core.Interfaces.ITemplateRenderer.Parse[T](String template, T model, Boolean isHtml)
   at FluentEmail.Core.Email.UsingTemplateFromEmbedded[T](String path, T model, Assembly assembly, Boolean isHtml)
   at WebDevX.Services.Email.Emails.VerifyEmail.CreateEmail() in E:\tmp\Paul\sources\vsts\WebDevX3Git\WebDevX\Services\Email\Emails\VerifyEmailEmail.cs:line 20
   at WebDevX.Services.Email.EmailFactory.CreateFromModel(IEmailModel model, String fromEmail, String fromName) in E:\tmp\Paul\sources\vsts\WebDevX3Git\WebDevX\Services\Email\EmailFactory.cs:line 35
   at WebDevX.Services.Email.EmailSenders.Base.EmailSenderBase`1.SendEmailAsync(IEmailModel model) in E:\tmp\Paul\sources\vsts\WebDevX3Git\WebDevX\Services\Email\EmailSenders\Base\EmailSenderBase.cs:line 32
   at WebDevX.Auth.Web.Services.RealAuthEmailService.SendVerifyEmailAsync(VerifyEmailModel model) in E:\tmp\Paul\sources\vsts\WebDevX3Git\WebDevX\Auth.Web\Services\RealAuthEmailService.cs:line 29
   at WebDevX.Auth.Web.Controllers.AccountController.Register(RegisterViewModel model, String returnUrl) in E:\tmp\Paul\sources\vsts\WebDevX3Git\WebDevX\Auth.Web\Controllers\AccountController.cs:line 442
   at Microsoft.AspNetCore.Mvc.Internal.ActionMethodExecutor.TaskOfIActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
   at System.Threading.Tasks.ValueTask`1.get_Result()
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeActionMethodAsync()
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeNextActionFilterAsync()
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ActionExecutedContext context)
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeInnerFilterAsync()
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextResourceFilter()
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResourceExecutedContext context)
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeFilterPipelineAsync()
   at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeAsync()
   at Microsoft.AspNetCore.Builder.RouterMiddleware.Invoke(HttpContext httpContext)
   at IdentityServer4.Hosting.IdentityServerMiddleware.Invoke(HttpContext context, IEndpointRouter router, IUserSession session, IEventService events)
   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Cors.Infrastructure.CorsMiddleware.Invoke(HttpContext context)
   at IdentityServer4.Hosting.BaseUrlMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware.Invoke(HttpContext context)

Package versions:

    <PackageReference Include="FluentEmail.Razor" Version="2.5.0" />
    <PackageReference Include="FluentEmail.SendGrid" Version="2.5.0" />

Do you have any ideas guys\girls? Is it related to the Class Library type of project?