ASP.Net Web Site Project - Errors Not Caught at Compile time
For the first time in my career, I'm working on an ASP.Net (v3.5) project that has been set up as a Visual Studio 2008/10 Web Site Project.
I'm not keen on this way of working this way for various reasons but for the moment and until such time as the company sees the virtue in working in an environment with namespaces, designer and project files etc., I have to continue with the existing codebase.
I've run into some odd issues since I began this but perhaps the oddest one of all is that althought VS lets me build the code, it doesn't reliably pick up compilation errors so these are not noticed until runtime.
I know the website model allows dynamic/hot compilation when a request is made for a speci开发者_如何学JAVAfic but I can't see why it wouldn't do this when I manually (F5) build/rebuild the project.
Its immensely annoying as you can imagine and I can't find a workaround. Could any StackOverflow person help with suome suggestions to make things better?
If you have a register command in your aspx or ascx file, and you have not registered the assembly in your project, this will not be picked up until runtime. Could this be the problem?
<%@ Register TagPrefix="Custom" Namespace="CustomControlNamespace" Assembly= "CustomControl" %>
If you include a web deployment project in your solution and set it up to pre-compile your site, it will pick up these types of errors as it will compile the markup pages along with the code behind, whereas at the moment, you are only compiling your code behind and designer files.
The web deployment project has an option to compile everything, including the ascx, aspx, and other things. It has saved me from errors markup several times.
http://msdn.microsoft.com/en-us/magazine/cc163448.aspx Uncheck "make updatable" to force a compile of everything. On large apps, this can take a long time. You know you have a complete compile when all the code behind files are gone and the ascx files say "this is a stub" when you open them.
Even after that much compilation, ASP.NET Profile, some xml serialization and other edge cases still cause some compilation at runtime.
The most likely reason for this is that there are compile errors in your markup pages. These do not get compiled when you build, only on first run.
精彩评论