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):
In my case, this problem happen, when I set MvcRazorCompileOnPublish to true in project file.
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
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)
I had the same problem and @penihel solution has worked for me!
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.
@OblivionSY I had the same problem and the easiest solution was to embed the cshtml files in the project.
@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
<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.
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?
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.
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.
@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.
https://github.com/aspnet/Mvc/issues/6021#issuecomment-290745919
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
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.
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.
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.
Most helpful comment
I solve the problem, putting this on csproj
The key is the "MvcRazorExcludeRefAssembliesFromPublish" tag