By Tristan Gaydon
it’s always frustrating when commencing a debugging session of an IIS hosted application in Visual Studio having to try and identify which worker process to attach to when you have multiple sites running.
To identify which process to attach to, I’ve long been a fan of the command “appcmd list wp” to find out which process ID is which application pool when debugging within visual studio;
More recently I got fed up with having to switch out of visual studio to my console window to run the command only to switch back into Visual Studio to get the debugger attached.
There had to be a better way. A way to execute the command from within Visual Studio.
In Visual Studio 2010 there was PowerConsole, a gallery extension that gave a Powershell prompt from within Visual Studio, but it isn’t supported in Visual Studio 2012. Researching further I came across a post on Stack Overflow related to Poweshell inside Visual Studio.
The second answer gave me an interesting lead;
I didn’t know that. Interesting.
Sure enough, a swift powershell command later;
$appCmd = "$Env:SystemRoot\system32\inetsrv\appcmd.exe"
&$appCmd list wp
Voila. Problem solved. Now I can quickly resolve the process ID of the application without having to leave visual studio. Happy days.
Clean Code: A Handbook of Agile Software Craftsmanship by Robert C Martin, Published 1 Aug 2008
Robert Martin aka “Uncle Bob” is a well known and well respected figure in the software development industry. He introduced the development world to SOLID in his principles of OOD article over ten years ago in 2003 and continues to publish, talk and teach software development.
The book is presented in three distinct section. The first thirteen chapters deal in detail with common problems found in code, how to avoid them in the first place and how to deal with them when they’ve already occurred.
The second section dives into three examples of successive refinement/refactoring on some real life code, illustrating the application of the principles covered in the first section.
The third and final section provided a reference encyclopaedia of code smells and heuristics, nicely summarised in this “clean code sheet sheet”.
The overriding message of the book is that as professional software developers we have a responsibility to “leave the campground cleaner than we found it”. This Boy Scout Rule is a great ethic. As a professional coder it’s not enough to “not make it any worse”, we all need to actively work to maintain our codebases and constantly strive to make them a little bit better through a process of constant refinement.
All of the code presented is in Java although most of the principles covered are applicable to any OO language and many of them to all languages.
In summary, Clean Code is a great book dealing with the nuts and bolts of practical everyday software development. I’d highly recommend it to any intermediate developer as a must read to help take their coding skills up a level. More experienced developers will have learnt most of the lessons the hard way through their own experience, however the book still provides value as a refresher and reference to common pitfalls and their solutions. I’m looking forward to reading the sequel, The Clean Coder: A Code of Conduct for Professional Programmers.
I’m unfashionably late to the party on this one. Whilst reading Professional MVC4 recently, Phil Haack mentions a NuGet package called MiniProfiler which his team found helpful in the development of the NuGet gallery. I made a mental note to have a look at.
I’m not quite sure how I managed to miss this before as both Scot Hanselman previously blogged about this in his post NuGet Package of the Week #9 - ASP.NET MiniProfiler from StackExchange rocks your world as did K Scott Allen in ELMAH and MiniProfiler In ASP.NET MVC 4.
MiniProfiler was designed by the development team at Stack Overflow. It’s a simple but effective in browser mini-profiler for ASP.NET, WCF and the .NET platform. Once installed and properly configured, MiniProfiler adds a little widget to every page on your site when running in localhost. This widget initially indicates the time taken by the server to process the request ;
Click on the widget and you’ll get profiling information for the current page. For example, below you can see that the a request to this site’s book review of dependency injection in .Net ran 5 SQL queries and spent 23.8% of the execution time in that SQL.
As a developer, Miniprofiler raises your awareness of what SQL statements are actually being executed. MiniProfiler will expose this information to you. Simply click on the “sql” links to see the generated SQL, as well as the containing method, as shown below.
Adding support for MVC
Adding the NuGet package MiniProfiler.MVC3 adds much better support for MVC applications by adding timing information for certain key points in the request life cycle, such as rendered views and partial views.
Inviting NHibernate to the party
NHibernate is a fabulous ORM, but it can have a tendency to disconnect the developer from thinking about the underlying SQL being generated and executed. definitely. NHibernate Profiler is great for this in a full on profiling/debugging session, but wouldn’t it be great to have this information more readily available?
Out of the box MiniProfiler won’t integrate with NHibernate, but fortunately, there’s a NuGet package for that! Just install MiniProfiler.NHibernate and then configure our NHibernate session to use this connection driver;
I don’t envisage that you’ll be replacing either dotTrace or NHibernate Profiler any time soon for detailed profiling/debugging, but to give you a quick overview of what’s going on Miniprofiler + MiniProfiler.MVC3 + MiniProfiler.Nhibernate is giving me a warm feeling thanks to these features;
It’s now installed on my current client’s codebase and is already helping the multi developer team improve the performance and efficiency of the codebase. I recommend you use MiniProfiler on your project. For The Win.