简体   繁体   中英

Some Razor Views are not Being Compiled on Publish in Visual Studio 2019

I have a bit of a complicated solution where I have two ASP.NET Core 2.2 projects and another project that they both share. The shared project contains four Razor views that I XCOPY into the other projects during pre-build.

All of that works great, but when I publish to IIS, those four views are not being compiled into the views assembly, and they're just being published as cshtml files. This unfortunately causes me to have lots of blank pages because those Razor views happen to be the form and table templates...

Does anyone know how I can resolve this and force the views to be compiled along with the rest of the project views?

UPDATE 1

I'm trying to get a Razor Class Library built at the moment, but I can't seem to figure out how to consume it properly.

UPDATE 2

I gave up on the RCL, it doesn't seem to be for normal MVC projects.

I moved the pre-build commands to a standalone batch file that I run manually in order to avoid the pre-build copying. It didn't help, the views are still being ignored for compilation and published as cshtml files. All razor files are marked as Build Action = Content, so I don't understand why those four are being ignored.

UPDATE 3

I revisited the RCL, and got it to work with normal MVC apps. It works locally just fine, but when I publish as Release to IIS, the cshtml files are still being copied and the compiled views are being ignored. I'm in the exact same spot as before the RCL. What can I do to make it stop publishing the cshtml files?

I stumbled onto an issue on the AspNetCore repository and it turns out this is a tooling issue. Unfortunately, it seems to be low in the priority list even though it can be a detrimental problem.

Anyway, the OP of the issue gave me an idea, which was to delete the folder with the published cshtml files and then recycle the apppool to for rediscovery of the compiled views.

Since I publish via FTP, I couldn't do anything during the publish. So, instead I made a PowerShell script to check for the existence of the offending folder every minute. If the folder is found, then it is deleted and the apppool is recycled.

I also got rid of the RCL and went back to my original pre-build XCOPY way. For now it works, but it would be better (of course!) if the tooling was fixed to avoid workarounds like this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM