Showing posts with label visual studio. Show all posts
Showing posts with label visual studio. Show all posts

Wednesday, August 18, 2010

Rockin' Visual Studio 2010's Productivity Power Tools

After listening to a recent podcast (sorry, can't remember which one!) on the joys of the Productivity Power Tools for Visual Studio 2010, I thought I'd give them another go. You see, I installed them on the same day I first installed VS2010 but it was all too much for me coming from VS2008 so I immediately removed the tools.

Well, on my second go-around I'm loving the control you now have over the document tabs. Three things in particular: vertical tabs, alphabetically sorted tabs, pinned tabs and regex colored tabs... ok, that was four things.

In the past I used to have to put up with VS2010 being able to show about 5 or 6 open documents via the tabs (I run duel 22 inch LCDs at some weird-ass resolution), anything else and I'd have to go to the annoying little drop down arrow. But check out this screenshot of my current layout with vertical tabs, not sure how many tabs I could get in there but it'd easily be 30-odd and they'd all be easily readable.

Using the regex colored tabs means each different file type has a different color plus I've set parent/child documents to be different shades of the same color (see the aspx and aspx.cs files and the ascx and ascx.cs files?). It ain't pretty but man can I find the file I'm after quick smart!

Having the tabs sorted alphabetically means related documents are stacked on top of each other, again making things easier to get at.

Lastly, pinning tabs means frequently accessed files are always in the same spot. I have my web.config and default.css within easy reach. No more hunting around in the Solution Explorer. Yay!

Here are my settings (click for full res):



Wednesday, November 18, 2009

LINQ To SQL Profiler And How To Swing It

[warning: technical post]

My friend showed me a cool profiler the other day by the smart chaps at Hibernating Rhinos which lets you see what is going on behind the scenes of the magic black box known as "LINQ To SQL" (L2S). I've been using LINQ to SQL for almost 2 years now and while it's far from perfect it makes my job (life!) much easier. Unfortunately by hiding the inner workings away from the developer by the time you come to look at the performance of your website (or desktop app) you're pretty much left in the dark. That's where L2SProf comes in. It hooks into your datacontext and gives you a great view of what's happening back there...


Now, the set up is pretty straightforward with L2SProf and involves adding a reference to a single DLL into your app (web or otherwise) then copying and pasting a single line of code into your startup method (e.g. Application_Start in global.asax for a website). Once you've done that you restart your application, crack open the included L2SProf.exe and voila, your LINQ to SQL datacontext's secrets are no longer secret... unless you're me. I got a big fat nothing.

After trying to sort it out with my friend and failing I jumped onto the support forums and posted a quick message asking for help. There was a bit of to-ing and fro-ing over email with not much accomplished. Then Oren Eini (AKA Ayende Rahien) popped onto the scene (then Skype) to give me some help.

First we tried writing the profiler data to a text file (a slight modification to that single line of code I mentioned earlier) and while the log file was created, nothing was written to it. Next we created a brand new web application from scratch and everything worked with the profiler showing my single datacontext call and its corresponding SQL code. Oren looked over the web.config from my original website and decided the problem wasn't in there. After fiddling around some more we came across a little bit of code I'd put in place to stop Visual Studio from trying to read my connection string from the data model project's app.config. This was our "aha" moment.

Normally you'd either have your DBML file (LINQ to SQL datacontext) in your website or if it's out in another project in your solution, you'd let Visual Studio control the database connections by dropping them into the app.config, that's not how I had it set up. This is the method I had in place in my DataContext.cs...

public MyDataContext() : base(ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString)
{
OnCreated();
}


I'll let Oren explain what was going on here...

"The problem with doing it this way is that you are forcing L2S to build a new model every time that you create a data context, that is quite expensive, from a perf point of view. L2S have to use reflection to get the values each and every time. A side affect of that is that it also kills the way L2S Prof works. Here is how to make it both performance and work with L2S Prof:"

public MyDataContext() : base(ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString, mappingSource)
{
OnCreated();
}


Once we did this everything fell into place, data access information pouring out of my website. So there you go, once again proving that if you don't do what Visual Studio wants you to do you can get into trouble.

Thanks a lot to Oren for his help and patience in helping me solve this problem. Now I need to go see how badly my website is performing.

Wednesday, December 3, 2008

View Code Without Right Clicking

Here's a little Visual Studio 2008 tip for you. I find myself right-clicking ASCX/ASPX files and selecting "View Code" frequently during the day and today I just had enough of it. So I went a hunting on the Googley internet and didn't find much of anything useful (mostly just hints on using F7 and Shift-F7 to switch between Code View and Design View, i.e. not what I was after).

Using the search box in the Visual Studio Keyboard options to narrow down the list I found this little gem (click the image to see the full size version). Just select "OtherContextMenus.SchemaExplorer.ViewCode" and assigned it to your hotkey of choice. I used F12 F1 but I may change this later on if I find it too cumbersome. Don't forget to hit the "Assign" button or nothing will happen.

So now when I'm editing the front-end code and want to get to the back end code I just whack the old F12 F1 key and voila!

EDIT: Dammit, I just realised that F12 is the hot key to go to a method's definition so I'm now giving F1 a go seeing as I never use the inbuilt help. You can get your answer via a Google search before the inbuilt MSDN help has even loaded.

EDIT: If you accidentally assigned F12 to View Code you can set it back to its original setting by assigning it back to Edit.GoToDefinition in the Keyboard settings.

Saturday, September 6, 2008

Tech.Ed Summary

Well, Tech.Ed Australia 2008 has come and gone leaving me with a bursting brain and a bursting belly.  Instead of going into detail about what is currently at the front of my mind I'm going to list a few bullet points in no particular order.  I may expand on these at a later date...
  • RFID is a good idea, if it works
  • The best thing you can do for UX is to chuck everything out that you don't need (i.e. the KISS principle) and to START with the design.
  • Empty drink fridges for most of Thursday are NOT cool
  • I'd like to see something ELSE running on the Microsoft Surface other than the photo app
  • Tips of the Show: Ctrl-. and Copy/Paste References in Visual Studio 2008
  • Full Text Search in SQL Server 2008 kicks ass
  • Scott Hanselmann is an absolute pisser and knows his stuff/audience
  • The Windows Mobility team are insane
  • Dr Neil tells it like it is (and is a bit of a stirrer)
  • I still prefer LINQ to SQL over LINQ to Entities
  • I can't decide if Adam Cogan was acting stoned
All up, it was well worth the time and expense (thanks J&A!) and I can't wait to get in to work on Monday to start fiddling with stuff.  Chucking my database on 2008 and the site on IIS7 (bai bai Cassini!). *fingers crossed*