giovedì, maggio 29, 2008

Asp.net "full" compile from Visual Studio

Asp.net automatically compiles aspx pages. The code-behind is compiled in different ways dependingif you choose to work with "Asp.Net web application" project or with a "Asp.net web site".
When you work on an aspx in visual studio and you build the project/solution, VS compile the code-behind of the aspx page. But not the code in the aspx itself. The aspnet engine will compile the aspx page the first time it will be requested.

OK. Fantastic... but.... if you did an error, also a simple syntax error, you'll get evidence of it when you page will run. Not good. I'd like to do "full compile" to check all the code.

An example: this code does not work. But Vs2005 does not show any errors.

<script runat="server">
public
static int Test()
{

return "text";

}

</script>



Another example: this code has a syntax error. Met2 is wrong. Met1 is the righe name. But again vs2005 does not show any errors.


<%=WebApplication1.Class1.Met2()%>




The only solution I have found is to do a full compile using aspnet_compiler.exe after the build process of Visual Studio. Add the following command in the Post-build event of the project:

$(MSBuildBinPath)\aspnet_compiler.exe -p $(ProjectDir) -v /





Now, you are notified if there are errors in you aspx pages.




Obviously compilation requires more time!

Nessun commento: