ASP.NET Core – InvalidOperationException: Cannot find compilation library location for package ‘Microsoft.Win32.Registry’
Add following line to your .csproj file:
I was publishing a project I am working on to web server (Linux) and I had an issue with Razor Pages.
However, it seems that this error occurs only when you precompile your Razor views (MVC views, Razor Pages). Why would you do that? Well, precompiling your views results in a smaller published bundle and faster startup time.
Precompile your views if you can!
For you to be able to do that you need to have enabled MvcRazorCompileOnPublish. You will do this inside of your .csproj file, by adding the following line:
If you are not running ASP.NET Core 2 and using All meta package then you need to install separate NuGet package for that: Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.
My concrete problem
My application was complaining about following:
InvalidOperationException: Cannot find compilation library location for package ‘Microsoft.Win32.Registry’
This happens when you have enabled precompilation of your views AND you have a class library that has embedded view or you are using a plugin that does the same thing (embedding views). In this case, you need to add an additional setting to your .csproj file:
This will continue publishing referenced DLLs inside of your publish directory.