-
Notifications
You must be signed in to change notification settings - Fork 10.2k
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
Embedded cshtml can't be found in ASP.NET Core MVC 3.0 #15315
Comments
@Nefcanto have you configured MVC to use runtime compilation by calling
Out of curiosity, is there a reason you're unable to use build-time compiled views? |
@Nefcanto Thanks for contacting us. The recommended approach is to use Razor Class Libraries instead of embedding the views in the assemlby. See for details https://docs.microsoft.com/en-us/aspnet/core/razor-pages/ui-class?view=aspnetcore-3.0&tabs=visual-studio |
@pranavkm I also prefer build-time. But for a lot of breaking changes that we encountered, we had to compromise in order to meet the market pressure and deadline. We simply used RuntimeCompilation because of another error and it solved it. I know it's spaghetti, but it's business. |
@javiercn your samples are too complicated, Too many technologies there. Razor, Blazor, Pages, Components, etc. and you keep adding new stuff. We can't keep up to date in business with all of your innovative ideas. And the point is your docs are out of date now I guess. But I'll give it a try because we're stuck now. Thanks for your guidance. |
@javiercn but for the older approach, can you give me some advice on what should I do to make our code work? |
Does the original suggestion from @pranavkm does not work? |
Based on this issue, I had to replace Based on @pranavkm comment, we realized that we don't need run-time compilation of Razor views at all. We need build-time compilation and that suffices for us. The suggestion of @javiercn (RCL) actually has a completely different layout than the old MVC layout in which Razor views were located in @pranavkm's suggestion worked. By adding Now I have two questions:
|
You can still keep this layout, razor class libraries work for razor pages and MVC views. Am I missing something? |
So, here's what I did:
To find out correct configuration, I created a project from Razor Class Library template, I checked
Now I'm stuck at configuring my
I can add a package reference to So, I'm stuck at this point. Can you help? I can send you log files of MSBuild in case of necessity. |
I've also removed the |
@Nefcanto The views should be found automatically in your web app project if it's referencing the class libraries. You can check the generated assembly from the class library and you'll see that it contains a bunch of assembly metadata attributes that specify all the views in the assembly, if those are not present, then something is not going according to plan. Also on your main web application you can check the list of application parts to see if your views are there. If any of those things is not present then there is something on your setup causing issues.
|
Here is a sample with all the views inside a class library. |
@javiercn would you have an idea of what could cause the dll of the host app to not display the The weirdest part though is that if I clean the solution, rebuild and restart, then it works 50% of the time, that's mesmerizing me... |
Okay, seems like the bug was related to Resharper Ultimate as after updating it, the assembly started containing the said metadata, and the ViewComponent started being available 100% of the time. |
I have a library in which MVC Razor views are defined. For example
\Views\Default\Index.cshtml
. And we use this configuration in.csproj
to reuse those views across projects:Now when we compile our library DLL, we can make sure that our
chtml
razor views are actually embedded inside the DLL file, insideResources
folder, using ILSpy.The we use this library inside an ASP.NET Core MVC Web Application, to reuse the
.cshtml
files.We use this line of code to register that library as a place for searching views:
This would work in ASP.NET Core MVC 2.2. But after upgrading to version 3.0, it's now complaining that:
What's wrong here?
The text was updated successfully, but these errors were encountered: