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

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

Closed
penihel opened this issue Jul 5, 2018 · 17 comments
Closed

Comments

@penihel
Copy link

penihel commented Jul 5, 2018

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
@fontanaricardo
Copy link

In my case, this problem happen, when I set MvcRazorCompileOnPublish to true in project file.

@penihel
Copy link
Author

penihel commented Jul 9, 2018

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

@Arcanst
Copy link

Arcanst commented Jul 10, 2018

I have the same problem with netcore 2.0 but sadly this doesn't resolve my issue. I'm still getting

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

Any other ideas how this could be resolved?

EDIT:
I actually had another error - Microsoft.AspNetCore.AntiForgery 2.0.3 could not have been found so I had to upgrade the base docker image from aspnetcore:2.0 to aspnetcore:2.0.8 (since I was using Microsoft.AspNetCore.All 2.0.8)

@dominikfoldi
Copy link

I had the same problem and @penihel solution has worked for me!

@OblivionSY
Copy link

Can anyone shed any more light on this issue? It works in Dev, but when i publish to folder, zip and deloy, I get this error.

I have included the aforementioned lines into the proj file.

I am loading the templates by file path, and these cshtml files did not get published, even though they are set as content and copy always. Any thoughts/Guidance would be very much appreciated.

@RemoteUserHrs
Copy link

@OblivionSY I had the same problem and the easiest solution was to embed the cshtml files in the project.

@OblivionSY
Copy link

@RemoteUserHrs Thanks, but that isn't really an option if you need to be able to edit the files quickly. What I ended up doing was putting this in the first section in the project:
<PreserveCompilationContext>true</PreserveCompilationContext> <MvcRazorCompileOnPublish>false</MvcRazorCompileOnPublish> <!--<MvcRazorExcludeRefAssembliesFromPublish>false</MvcRazorExcludeRefAssembliesFromPublish>-->

Can't remember if I tweaked anything else, but now my publish folder includes a refs folder with all the aspnet core dlls and it seems to have gone away. I may revist this, but since the site was due to go live today it was a case of quickest fix wins.

peterkeating added a commit to moov2/website-core that referenced this issue Oct 29, 2018
Following suggestions from various links (couple displayed below)

- toddams/RazorLight#203
- OrchardCMS/OrchardCore#1156
@sguryev
Copy link

sguryev commented Nov 6, 2018

Hey everybody,

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

@OblivionSY your sample (#203 (comment)) has the latest line commented which is original one from the @penihel response (#203 (comment)). 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?

@OblivionSY
Copy link

OblivionSY commented Nov 8, 2018

I am using this package <PackageReference Include="RazorLight" Version="2.0.0-beta1" /> will update in a quieter period I guess. I also don't have those packages you're using, so cannot comment on that I am afraid.

@sguryev
Copy link

sguryev commented Nov 9, 2018

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

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

@sguryev
Copy link

sguryev commented Nov 9, 2018

@OblivionSY

I am loading the templates by file path, and these cshtml files did not get published, even though they are set as content and copy always. Any thoughts/Guidance would be very much appreciated.

aspnet/Mvc#6021 (comment)

Since your application has a project reference, you would have to additionally change WebApp to copy the precompiled view from the library to the output \ publish directories

@letrape
Copy link

letrape commented May 15, 2019

This kind of problem happen me a lot, usally in old app services not updated to the latest changes on asp net core environment.

So one of my works arounds is to create a new deployment slot and publish to the new slot. Usually this kind of errors solved in the new slot i dont know why but i guess it forces azure to create a new "image" with the latest updates on the runtime, then I just need to switch the slots.

@ZombiesWithCoffee
Copy link

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.

@joaocte
Copy link

joaocte commented May 8, 2020

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

this resolve in .net core 3.1.

@xantari
Copy link

xantari commented Nov 16, 2021

Getting this same error upgrading a project from .NET Core 5.0 to .NET Core 6.0. Nothing above has solved this issue yet.

@jzabroski
Copy link
Collaborator

@xantari This issue is about .NET Core 2.1 and .NET Core 3.1.

Repository owner locked as resolved and limited conversation to collaborators Nov 16, 2021
@jzabroski
Copy link
Collaborator

This issue is now locked. If the FAQ in the README or @penihel 's suggestion does not work, open a new issue and follow the issue template. Also try to create a repro , as that will likely solve your problem through explaining it to yourself.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests