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.

Answers


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.


Need Your Help

how to generate a Custom Class via t4?

c# design-patterns code-generation t4

I am trying to generate the below code via T4.

PHP mail() screwing up HTML href's

php html email formatting

I have a mail() function going in a PHP script. It sends HTML just fine - the headers are set up correctly. What IS incorrect, however, is the representation of HREFs - they come out all garbled in

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.