Can I precompile my ASP.NET MVC application?
I tried to precompile my ASP.NET MVC application and deploy it to an IIS6 box (with wildcard mapping), however I am getting an error with rendering partial views (user controls). Its working fine on my dev machine before precompiling.
The error is:
Server Error in '/' Application. The partial view 'ListGrid' could not be found. The following locations were searched: ~/Views/Initiative/ListGrid.aspx ~/Views/Initiative/ListGrid.ascx ~/Views/Shared/ListGrid.aspx ~/Views/Shared/ListGrid.ascx
I checked Views\Shared for the file and it was not there, which I thought was normal because its precompiled. But just for giggles I put a blank file in that folder names ListGrid.ascx, but then I got this error:
Server Error in '/' Application. The file '/Views/Shared/ListGrid.ascx' has not been pre-compiled, and cannot be requested.
I googled and searched SO but could not find any similar problems, but had no luck.
Although you can precompile an MVC site the ascx and aspx view files are not in the compiled dll only the .cs files are. You will still need to deploy the .aspx and .ascx view files.
Hope this helps
You can precompile an MVC app by placing this in the post-build actions in project properties:
C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_compiler -p "$(ProjectDir)." -v /$(ProjectName)
This takes a little longer than without it, however you get the added ability to detect some errors that would occur at runtime prior to deployment.
Compilation will fail if you have invalid code in your views or are missing views by using this method.