The opinions expressed in these materials are my own and are not necessarily those of Microsoft.
Copyright © Microsoft Corporation. All rights reserved. Unless otherwise indicated, all source code provided is licensed under the Microsoft Public License (Ms-PL).
This post is a bit overdue but better late than never. So let’s talk about Visual Studio Update 1…
Soma originally introduced Update 1 in his November 26th post here:
Since some of you may want to install this update immediately there are a few options for you.
From inside the IDE, go to Tools | Extensions and Updates:
Then look under the updates section and install from there:
If you want a more direct route you can click this link: http://go.microsoft.com/?linkid=9821199
You will get this dialog and can just click Run to execute the small .EXE and begin the online install:
Although many believe you can only install via online resources this is actually not true. A quick look at vsupdate_KB2707250.exe /? shows us the /layout switch:
So when I run vsupdate_KB2707250.exe /layout c:\ziptemp\vsup1 on my system this is the dialog I get:
This will download the source files to the designated location so you can make them available on a network share, thumb drive, or other media for stand-alone installation.
The most obvious question is, “Why should I care?” Despite the bug fixes and new features, this particular update represents a major shift in the timing for delivery. We have now committed to a shorter update cycle so we can deliver critical fixes and incorporate new features more quickly. What this means for you in real terms is that blocking issues may be resolved much more quickly and/or you will get a new feature that will help you get work done better/faster/stronger.
So what exactly did we deliver? Fundamentally there were two things we provided: Bug Fixes and New Features. You can find all the details here:
I’m going to repeat the bug fixes here and then address the new features in another article right after this one.
After an extended period of time looking for the list of bug fixes included in the package I was initially unable to find a comprehensive list anywhere. It looks like the team recognized there was a gap and updated the KB article on 1/13 to include all the relevant information. I’ll just repeat the information here verbatim for convenience.
Menu: Edit -> Advanced -> Tabify Selected Lines; Edit -> Advanced -> Untabify Selected Lines Command: Edit.TabifySelectedLines; Edit.UntabifySelectedLines;Edit.ConvertTabsToSpaces;Edit.ConvertSpacesToTabs Versions: 2008,2010Published: 3/14/2010Code: vstipEdit0028
Some people prefer spaces, others prefer tabs. Well you can have it any way you want it with this next item. You can convert spaces to tabs and convert tabs to spaces on your selected lines. There are a couple of ways to do this and each has different results:
Tabify / Untabify
If all you want to do is convert leading spaces to tabs (or vice versa) then you would use the Tabify/Untabify commands. First, start out with a line with some leading spaces (NOTE: You don't have to select the entire line for this to work as long as any part of the line is selected it will perform the action):
Now go to Edit -> Advanced -> Tabify Selected Lines:
And you should get the leading spaces converted to tabs:
Obviously, to change leading tabs to spaces you would use Untabify Selected Lines:
ConvertSpacesToTabs / ConvertTabsToSpaces
Okay, so what if you want ALL spaces to tabs? Well you have to use a command to do that and will have to make a custom keyboard mapping. The commands you are interested in are Edit.ConvertTabsToSpaces and Edit.ConvertSpacesToTabs. Here is what ConvertSpacesToTabs does to our example (NOTE: For these commands you have to select everywhere you want to convert it will not automatically convert the entire line in case you just want to convert a part of the line):
As you can see, almost all spaces are converted to tabs. Since spaces are converted to tabs in increments of 4, if you have, say, 6 spaces it will result in a tab and 2 spaces left over. That is why there are some left over spaces in the example. And, naturally, if we select these lines and run ConvertTabsToSpaces this will be the result:
And now you know how to convert tabs to spaces and spaces to tabs. Have fun!
Keyboard: CTRL + R, CTRL + WMenu: Edit -> Advanced -> View White SpaceCommand: Edit.ViewWhiteSpaceVersions: 2008,2010Published: 4/9/2010Code: vstipEdit0043
I've hijacked today's tip to remind everyone that next Monday I will start giving away $100 ThinkGeek gift certificates (one every day for about 30 days). For details of my evil plan, go here. Also, make sure to sign up for a Visual Studio Launch event in your area. Happy coding!
Download the seriously cool Tip of the Day Extension to get the daily tips delivered to your Start Page!
Ever want to see the white space you are working with? Maybe you want to know if your spaces are tabs or you have extra spaces on lines. It's easy to view white space. Just go to Edit -> Advanced -> View White Space (CTRL + R, CTRL + W) to go from this:
Menu: Tools -> Options -> Environment -> AutoRecoverVersions: 2008,2010,2012,2013Published: 6/30/2010Code: vstipEnv0019
WARNING: Read the comments associated with this post as there are multiple complaints that this features doesn't work as expected. Read this thread from the engineering folks about usage with versions VS2010 and older.
Perhaps your best friend is the AutoRecover feature. It can be a real life saver if the dev environment crashes or there is a power outage or a meteor hits your cube (okay, maybe not that last one). It's very simple to use, just go to Tools -> Options -> Environment -> AutoRecover:
If you want to turn this feature off you can deselect the "Save AutoRecover information every" checkbox. Of course, if you do this we will all laugh at you when you lose important work because you didn't have it and I will personally blog about it so everyone knows--you might want to leave it on--just saying. Here is what the other options do:
X minutes - determines how often files have AutoRecover information saved. The default is 5 minutes but you can adjust up or down depending on usage. There is an inverse relationship between this value and the frequency of your updates to code. If you make more frequent updates to code then have a lower number here. Fewer updates to code mean you can increase this number if you desire. If you are going to make a mistake here make it on the side of a number that is too low rather than too high. It's better to take any performance hit from file I/O than to lose a ton of work.
X days - used to decide how long AutoRecover files are kept in the Backup Files directory. The default is 7 days which is usually adequate for most situations. If you work with a lot of projects over a short period of time then you may want to decrease this number to keep the Backup Files directory more clear. If you are going to guess on this value then it's better to guess high and lower the number as needed.
Let's be clear on what a is exactly saved and where it is saved. First, recovered files are stored at \...\My Documents\Visual Studio <version>\Backup Files\<projectname>. Not every file is saved here. Let me show you an example:
Here is the backup folder for one of my solutions when I create it in Visual Studio:
Obviously the folder is empty. Now let me make a change to a file and save the change. Then I'll wait 5 minutes to see the result:
Still nothing because there is no need to recover a saved file. But let me make a change to a file without saving it and wait another 5 minutes:
NOW we have AutoRecover information because if there is crash we will have to make a decision to recover the unsaved changes or keep the last saved version. This is essentially the function of AutoRecover.
When you do finally have to recover a file, this is the dialog you will get:
Recovered files - lists the file(s) that can be recovered with a a checkbox to select/deselect the file as well as basic information.
<File Name> Summary - shows detailed information about the currently selected file including date/time info, location of the backup file, and destination location where the file will be recovered to.
Recover Selected Files - performs a recovery action on the file(s) selected copying the recovered source file to the previously indicated destination.
Do Not Recover - closes the dialog box without recovering any of the files listed.
Keyboard: CTRL + -; CTRL + SHIFT + - Menu: View -> Navigate Backward; View -> Navigate Forward Command: View.NavigateBackward; View.NavigateForward Versions: 2008,2010Published: 3/1/2010 Code: vstipEdit0024
The editor remembers locations when you move in a single command more than several lines away from where you are currently working, or if you edit in a particular location that is not adjacent to the last place you edited.
The goal is to remember interesting locations so that you can recall where you have been working without remembering so many locations the feature is not useful (such as every character typed, or every line entering several new lines of code one right after the other).
A go-back marker is dropped under the following conditions:
An incremental search (including reverse) leaves a go-back marker at the beginning of the search and another one at the end.
A Go To Line action, like CTRL + G, or a mouse-click that moves the cursor 11 lines or more from the current position drops a go-back marker at the new location.
A destructive action (like hitting Backspace) after having moved the cursor to a new location drops a go-back marker.
Doing a search, like Ctrl+F, drops a go-back marker at the found location.
Opening a file drops a go-back marker wherever the cursor was on the old file and drops another on the opened file.
So with all that, welcome back to the wonderful world of the Navigate buttons (and keyboard shortcuts, too)! These gems make travelling around your code much, much easier:
Menu: Tools -> Options -> Projects and Solutions –> General Commands: View.TrackActivityinSolutionExplorer Versions: 2005,2008, 2010 Published: 3/29/2010 Code: vstipProj0011
Note: Several people have asked if you can turn this feature on and off at will. You can if you bind the View.TrackActivityinSolutionExplorer command to a keyboard shortcut.
By default, VS2010 will track the current file you are editing in Solution Explorer. It looks like this:
Notice that the current file being edited is also selected in Solution Explorer automatically. This is a great way to keep track of where you are in the solution when you are working with a lot of files. You can turn it off if you want. Just go to Tools -> Options -> Projects and Solutions -> General -> "Track Active Item in Solution Explorer" and uncheck the option to turn this feature off.
If you haven't come across this yet you will at some point. There is a known issue with Vista and activation. You can get the details for common errors at this KB article, but the steps are pretty straightforward:
1) Go to Control Panel...System and Maintainence...System
2) Scroll to the bottom of the screen
3) Click on Change Product Key
4) Type in your key
5) Click Next and follow the rest of the steps in the wizard
That's it! Soon you'll be enjoying Vista and be activated :)
Several people have asked me how to convert from VMWare to VHD format. Here are the steps to get you going:
1) Download VMDK to VHD converter free tool from http://vmtoolkit.com/files/folders/converters/entry8.aspx I had successfully converted disks 29Gb in size
2) “Prepare” your VMWare image by following steps in http://searchservervirtualization.techtarget.com/tip/0,289483,sid94_gci1239063,00.html or http://www.jaylee.org/post/2008/10/How-to-convert-a-big-VMWare-VMDK-into-an-Hyper-V-VHD.aspx
3) Install Virtual Server 2005 (Std/Ent, R2 or not – but if R2, select Enterprise and install the one with SP1 – it’s all free and on the web…)
4) Make sure your VMWare image contains at least one IDE drive before final shutdown (VS2005 will need it). Take note of drives inside VM (C,D,E…)
5) Convert each one VMW files into VHD
6) Attach “system” disk as a main disk in new Virtual Server image
NOTE: You could roll out Virtual Machine Manager and use the “conversion” feature in one step instead of six.
Thanks to Oleg Kofman from MS who provided me this info...
Menu: Tools -> Options -> Projects and Solutions -> General Versions: 2008,2010Published: 3/26/2010 Code: vstipProj0008
If you don't like seeing the solution file in Solution Explorer, you can easily hide it (or show it if you have it hidden). First, let's review what the default looks like with the solution file showing:
Now if we go to Tools -> Options -> Projects and Solutions -> General and uncheck "Always show solution":
This is the result:
SPECIAL NOTE: This only works when there is one project in the solution. If you have multiple projects in your solution it will ignore this setting and give you the default view.
SKU: Premium, Ultimate
Versions: 2008, 2010
As we continue looking at code metrics in Visual Studio (see vstipTool0129, “Calculating Metrics”), it’s time to look at class coupling. Class coupling also goes by the name Coupling Between Objects (CBO) as originally defined by [CK94]. Basically, class coupling is a measure of how many classes a single class uses. A high number is bad and a low number is generally good with this metric. Class coupling has been shown to be an accurate predictor of software failure and recent studies have shown that an upper-limit value of 9 is the most efficient [S2010].
According to the MSDN documentation, class coupling “[m]easures the coupling to unique classes through parameters, local variables, return types, method calls, generic or template instantiations, base classes, interface implementations, fields defined on external types, and attribute decoration. Good software design dictates that types and methods should have high cohesion and low coupling. High coupling indicates a design that is difficult to reuse and maintain because of its many interdependencies on other types.”
The concepts of coupling and cohesion are clearly related. To keep this discussion on topic, I will not get into depth with cohesion other than to give a brief definition from [KKLS2000]:
“Module cohesion was introduced by Yourdon and Constantine as ‘how tightly bound or related the internal elements of a module are to one another’ [YC79]. A module has a strong cohesion if it represents exactly one task […], and all its elements contribute to this single task. They describe cohesion as an attribute of design, rather than code, and an attribute that can be used to predict reusability, maintainability, and changeability.”
Let’s look at class coupling in action. First, create a new console application and create a new class called Person with some properties in it then immediately calculate the code metrics:
Notice the class coupling is 0 since this class doesn’t use any other classes. Now create another class called PersonStuff with a method that creates an instance of Person and sets the property values. Calculate the code metrics again:
See how the class coupling value goes up? Also notice that, no matter how many properties we set, the class coupling value just goes up by 1 and not by some other value. Class coupling measures each class only once for this metric no matter how much it is used. In addition, can you see that DoSomething() has a 1 but the constructor, PersonStuff(), has a 0 for its value? Currently there is no code in the constructor that is using another class.
What if we put code in the constructor that used another class? Here is what you get:
Now the constructor clearly has code that uses another class and the class coupling metric shows this fact. Again, you can see the overall class coupling for PersonStuff() is 1 and DoSomething() is also 1 to show that only one external class is being used no matter how much internal code we have that uses it.
Next, let’s create another new class. I’ll call my class Blah and create some properties inside it:
Now consume the class in our DoSomething() method within the PersonStuff class and calculate code metrics again:
As you can see, the class coupling for the PersonStuff class goes up to 2 and, if we drill into the class, we can see that the DoSomething() method has the most coupling in it but the constructor still only consumes 1 class. Using these metrics we can see the overall max number for a given class and drill down into the details on a per-member basis.
As I mentioned with cyclomatic complexity (see vstipTool0131, “Code Metrics - Cyclomatic Complexity”), there is no limit that fits all organizations. However, [S2010] does indicate that a limit of 9 is optimal:
“Therefore, we consider the threshold values […] as the most effective. These threshold values [for a single member] are CBO = 9[…].” (emphasis added)
When using code analysis, the Extended Design Guideline rule set contains a maintainability area:
Inside the maintainability area is a rule for class coupling:
This rule issues a warning when the class coupling is excessive. You can learn more about the rule here:
Unfortunately, the documentation doesn’t talk about the thresholds set for this rule but I did find a description on the Code Analysis Team Blog (http://blogs.msdn.com/b/codeanalysis/archive/2007/11/15/code-metrics-as-check-in-policy.aspx): “Warning at above 80 for class and above 30 for a method”. These seem abnormally high but at least provide an extreme upper limit. If you hit this warning then something is almost certainly wrong.
Chidamber, S. R. & Kemerer, C. F. (1994). A Metrics Suite for Object Oriented Design (IEEE Transactions on Software Engineering, Vol. 20, No. 6). Retrieved May 14, 2011, from the University of Pittsburgh web site: http://www.pitt.edu/~ckemerer/CK%20research%20papers/MetricForOOD_ChidamberKemerer94.pdf
Kabaili, H., Keller, R., Lustman, F., and Saint-Denis, G. (2000). Class Cohesion Revisited: An Empirical Study on Industrial Systems (Proceedings of the Workshop on Quantitative Approaches in Object-Oriented Software Engineering). Retrieved May 20, 2011, from Université de Montréal web site http://www.iro.umontreal.ca/~sahraouh/qaoose/papers/Kabaili.pdf
Subramanyam, R. & Krishnan, M. S. (2003). Empirical Analysis of CK Metrics for Object-Oriented Design Complexity: Implications for Software Defects (IEEE Transactions on Software Engineering, Vol. 29, No. 4). Retrieved May 14, 2011, from University of Massachusetts Dartmouth web site http://moosehead.cis.umassd.edu/cis580/readings/OO_Design_Complexity_Metrics.pdf
Shatnawi, R. (2010). A Quantitative Investigation of the Acceptable Risk Levels of Object-Oriented Metrics in Open-Source Systems (IEEE Transactions on Software Engineering, Vol. 36, No. 2).
Edward Yourdon and Larry L. Constantine. Structured Design. Prentice Hall, Englewood Cliffs, N.J., 1979.