Introduction
When we build a specified Web Application (with C#/VB.NET compiler), normally the compiler compiles them into a DLL with the same name as the web application into the bin folder. This bin folder has been designation with Execute or Script Permission and no read permission. This is to ensure that the DLL is not downloaded by anybody and decompiled. Our concern here is to optimizing the way the compiler reports back, the results to us.
Perhaps some of the thoughts might be bit redundant, but we went through the hurdles while generating the documentation with NDOC, after which, I just thought an article on this would be helpful with .NET development fraternity worldwide.
Compiler Warnings (First Level)
We normally declare identifiers at class level, method level etc. When we don't use these the compiler may point out that the specified identifier has never been used. Significant among them is the case where you have a private scope identifier, which has not been referred at all in the class and there is no public property to get/set the value for the same.
Next, when we use
Try and
Catch Block to catch
Exception, we normally say as
catch (Exception ThisException)
{
Response.Write ("There seems to be some problem. My method
threw an exception");
}
The above block would raise a compiler warning since the identifier ThisException has never been used. Perhaps you can temporarily dump into
Debug.Write("The class TestClass had a problem. Here are the details "
+ThisException.StackTrace + " and " +
ThisException.Message);
The above block would be passed by the compiler without any errors/warnings. But this as it is does not serve any purpose, All these Debug.Write statements are visible within Microsoft Visual Studio .NET Debug window. And when the application rolls out into production environment, we can change the Project Build Option into Release when all Debug Symbols would be removed and a cleaner and smaller Assembly would be generated by the compiler.
There are some options like amount of ConnectionOpen and ConnectionCloses, FileStreamsOpen and FileStreamsClosed, depending upon the nature of the application itself. In these cases, you can use Tracing. Tracing, has effects only when it has been enabled from Web.Config and works till the level that it has been configured to. So if you would like to monitor number of database connections being opened and closed or amount of FileOpens and Closes as these are bit blocking operations involving more resources, you can use Tracing as it would generate enough logging information that you can use to detect, diagnose and assess the situation.
Tracing is the biggest gift in ASP.NET application compared to any other framework and is beyond the scope of discussion in this small article. Perhaps the following article is a good point of understanding on Tracing in ASP.NET. An Article on Tracing in ASPFree.com
Well! Let's come back to our original discussions. Normally it is better to heed to the compiler warnings other than ignoring them. A warning actually stands for some potential problem. Like an un-initialized object, if when used, may cause a System.NullReferenceException. Possibly, that is why, there is a compiler option like 'Treat Warnings As Errors', which when enabled, will halt compilation, even if warnings are encountered. By default, this option is off.
Compiler Warnings (with XML Document Option)
When we try to compile the project with XML document generation option, the compiler will take the responsibility of checking whether all publicly visible properties have valid XML Comments. To satisfy a proper XML generation, so that the generated CHM file with tools like NDOC etc have valid comments filled in, you may need to feed the following comment just above the publicly visible entity (method/property/identifier/enumeration), whichever is public or protected.
<summary>
Some sample Summary Comments Tag. Visual Studio .NET normally uses this
to show you a description of what the method does that carries the
summary comments.
</summary>
Perhaps there are a lot more Documentation Comments that needs to be used for generating a documentation comments for an application. A complete documentation of documentation comments is available from the following MSDN URL:
Changing Configurations:
Perhaps while we roll out the web application into production, it is normally a recommended option to change the Build Configuration to Release mode, since in Release configuration, a lot of debug information are not saved and the compiler tries to make application assembly as compact and as fast as possible, as far as my little knowledge could analyze.Perhaps in larger organizations, there would be seperate teams to manage this Release Configuration. But in smaller organizations, it would be the responsibility of the development team itself to manage Debug and Release Configurations. Isn't it?
Scheduled Builds
Perhaps once we configure our web application in Release Mode, we can save this Solution file and use an automated Batch File or a freeware tool like BuildIt, which can automatically take a latest version from SourceControl also and do a complete Build and sending the BuildReports to us. I had an opportunity to download BuildIt and play around it from the following URL and our team really liked it:
I think for internal test builds, the above Scheduled Builds would really be useful. Once all BuildIt reports are ok, during final deployment, a personnel can verify everything and transfer the same to the production. Isn't it?
Conclusion
I think the above article should be really useful and a
good starting point to make a kind of efficient builds of the applications. The article might not be an exhaustive coverage of elegant builds and use of Traces, but I hope, it would be make a humble start in this direction.