I published an OC application on a server and hosted it on IIS and I had this error:
Cannot find compilation library location for package 'Microsoft.Win32.Registry'
I don't know what is the exact reason but I managed to fix it by adding this in my .csproj :
<MvcRazorExcludeRefAssembliesFromPublish>false</MvcRazorExcludeRefAssembliesFromPublish>
See https://github.com/dotnet/core-setup/issues/2113 for more explanations
I know an expert about these kind of things, he lives in France near Valence ...
I just figured out that OrchardCore.Cms.Web.csproj has these options:
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<PreserveCompilationContext>true</PreserveCompilationContext>
<MvcRazorCompileOnPublish>true</MvcRazorCompileOnPublish>
<MvcRazorExcludeRefAssembliesFromPublish>false</MvcRazorExcludeRefAssembliesFromPublish>
</PropertyGroup>
Yes, we precompile views so when publishing we don't need to output compile time assemblies in the refs subfolder.
Needs documentation to explain which properties to add in .csproj when you use OC.Targets nuget package or else it won't work when it is deployed on IIS.
As a reminder.
If we don't use the razor precompilation tool we just need PreserveCompilationContext = true.
If we use the razor precompilation tool and we also use liquid tag helpers, we still need PreserveCompilationContext = true and we need MvcRazorExcludeRefAssembliesFromPublish = false.
If we use the razor precompilation tool and we don't use liquid tag helpers, we can use PreserveCompilationContext = false without defining MvcRazorExcludeRefAssembliesFromPublish (true by default).
I set this up
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<PreserveCompilationContext>true</PreserveCompilationContext>
<MvcRazorCompileOnPublish>true</MvcRazorCompileOnPublish>
<MvcRazorExcludeRefAssembliesFromPublish>false</MvcRazorExcludeRefAssembliesFromPublish>
</PropertyGroup>
however still throws the same error. I'm currently on VS 2017 15.5.5
This will be included inthe csproj when you create a Cms.Web application using the dotnet new template
for OC:
<PreserveCompilationContext>true</PreserveCompilationContext>
<MvcRazorCompileOnPublish>true</MvcRazorCompileOnPublish>
<MvcRazorExcludeRefAssembliesFromPublish>false</MvcRazorExcludeRefAssembliesFromPublish>
Just tried it works on my machine without the last line so that no refs folder is generated on publishing. Normally we don't need it because views are now precompiled and embedded in each module assembly on building by using the Sdk.Razor. And we fixed the "issue" where razor compilation was still triggered.
If there are views defined at the app level, they are precompiled by the old tool on publishing. But normally here also we don't need the refs folder.
That said, for a given module / theme using Sdk.Razor, for the precompilation to be effective, right now (with this sdk version) the module / theme needs to reference the .AspNetCore.Mvc package directly in its csproj file. If you forget this, views will not be precompiled, only embedded. In this case the razor compilation is done at runtime and needs compilation assemblies in the refs folder.
So, maybe better to re-add this line in the OC.Cms.Web application project file. On another side you will not see that some views of some modules are not precompiled.
<MvcRazorExcludeRefAssembliesFromPublish>false</MvcRazorExcludeRefAssembliesFromPublish>
Hmm, maybe something to add to the documentation
A module needs to use the razor sdk to have its razor views precompiled.
<Project Sdk="Microsoft.NET.Sdk.Razor">
But, for the precompilation to be effective you also need in each module project file.
<PackageReference Include="Microsoft.AspNetCore.Mvc" />
Thank you for the explanations @jtkech .
I migrated my OC website to the latest version and I was wondering what to change:
<TargetFramework>netcoreapp2.1</TargetFramework>
and then which package use:
Microsoft.AspNetCore.All (that is what I do currently) or Microsoft.AspNetCore.App (like in OrchardCore.Cms.Web)
As it is in the current OC.Cms.Web application.
And if you want all your modules views to be precompiled, don't forget to add to each module a direct reference to Microsoft.AspNetCore.Mvc.
Otherwise you will have razor compilation at runtime and then you will need the refs folder, and then you will need to re-introduce this line in your app project file.
<MvcRazorExcludeRefAssembliesFromPublish>false</MvcRazorExcludeRefAssembliesFromPublish>
@agriffard for infos
So, i'm working on a PR that will be ready for tomorrow
We will use the same Sdk.Razor (inherited by Sdk.Web) to precompile views defined at the application level, as we do for modules / themes views. So you will have to remove this line.
Then, because each modules should precompile its views, it should reference AspnetCore.Mvc directly because it is a requirement. So, @sebastienros said to me to not re-introduce.
So at this point it will just be by default.
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<TieredCompilation>true</TieredCompilation>
<PreserveCompilationContext>true</PreserveCompilationContext>
</PropertyGroup>
I tried all the above advices, but I still got the following error:
System.UnauthorizedAccessException: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
at System.Runtime.Loader.AssemblyLoadContext.LoadFromStream(IntPtr ptrNativeAssemblyLoadContext, IntPtr ptrAssemblyArray, Int32 iAssemblyArrayLen, IntPtr ptrSymbols, Int32 iSymbolArrayLen, ObjectHandleOnStack retAssembly)
at System.Runtime.Loader.AssemblyLoadContext.LoadFromStream(Stream assembly, Stream assemblySymbols)
at System.Reflection.Assembly.Load(Byte[] rawAssembly, Byte[] rawSymbolStore)
at Microsoft.AspNetCore.Mvc.Razor.Internal.SharedRazorViewCompiler.CompileAndEmit(RazorCodeDocument codeDocument, String generatedCode) in C:\projects\orchard2\src\OrchardCore\OrchardCore.Mvc.Core\SharedRazorViewCompiler.cs:line 395
at Microsoft.AspNetCore.Mvc.Razor.Internal.SharedRazorViewCompiler.CompileAndEmit(String relativePath) in C:\projects\orchard2\src\OrchardCore\OrchardCore.Mvc.Core\SharedRazorViewCompiler.cs:line 353
at Microsoft.AspNetCore.Mvc.Razor.Internal.SharedRazorViewCompiler.OnCacheMiss(String normalizedPath) in C:\projects\orchard2\src\OrchardCore\OrchardCore.Mvc.Core\SharedRazorViewCompiler.cs:line 212
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.AspNetCore.Mvc.Razor.Internal.DefaultRazorPageFactoryProvider.CreateFactory(String relativePath)
at Microsoft.AspNetCore.Mvc.Razor.RazorViewEngine.CreateCacheResult(HashSet``1 expirationTokens, String relativePath, Boolean isMainPage)
at Microsoft.AspNetCore.Mvc.Razor.RazorViewEngine.OnCacheMiss(ViewLocationExpanderContext expanderContext, ViewLocationCacheKey cacheKey)
at Microsoft.AspNetCore.Mvc.Razor.RazorViewEngine.LocatePageFromViewLocations(ActionContext actionContext, String pageName, Boolean isMainPage)
at Microsoft.AspNetCore.Mvc.Razor.RazorViewEngine.FindView(ActionContext context, String viewName, Boolean isMainPage)
at Microsoft.AspNetCore.Mvc.ViewEngines.CompositeViewEngine.FindView(ActionContext context, String viewName, Boolean isMainPage)
at Microsoft.AspNetCore.Mvc.ViewFeatures.ViewResultExecutor.FindView(ActionContext actionContext, ViewResult viewResult)
at Microsoft.AspNetCore.Mvc.ViewFeatures.ViewResultExecutor.ExecuteAsync(ActionContext context, ViewResult result)
at Microsoft.AspNetCore.Mvc.ViewResult.ExecuteResultAsync(ActionContext context)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeResultAsync(IActionResult result)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextResultFilterAsync[TFilter,TFilterAsync]()
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResultExecutedContext context)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.ResultNext[TFilter,TFilterAsync](State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeResultFilters()
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 Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware.Invoke(HttpContext context)
at Microsoft.AspNetCore.Server.IISIntegration.IISMiddleware.Invoke(HttpContext httpContext)
at OrchardCore.Modules.ModularTenantRouterMiddleware.Invoke(HttpContext httpContext) in C:\projects\orchard2\src\OrchardCore\OrchardCore.Modules\ModularTenantRouterMiddleware.cs:line 82
at OrchardCore.Modules.ModularTenantContainerMiddleware.Invoke(HttpContext httpContext) in C:\projects\orchard2\src\OrchardCore\OrchardCore.Modules\ModularTenantContainerMiddleware.cs:line 89
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
This is my csproj file:
\
\
\
\
\
\
\
\
\
\
\
\
\
\
\
\
\
I ran out of ideas
Most helpful comment
I just figured out that OrchardCore.Cms.Web.csproj has these options: