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).
NOTE: This is an older feature. I’ve updated the information for VS2013.
This one is a little known feature you can take advantage of when working with your code. Assuming you have some unformatted code:
You can format the entire document by going to Edit -> Advanced -> Format Document (CTRL+K, CTRL+D) to get this:
You can also do this with just a selection of code:
Go to Edit -> Advanced -> Format Selection (CTRL+K, CTRL+F) to get this:
I won’t go deep into it here but it’s important to remember that the automated formatting follows the default rules you can easily change by going to Tools | Options | Text Editor | [Language] | Formatting in most cases. For example, to change the HTML rules go to Tools | Options | Text Editor | HTML | Formatting:
In the case of HTML, you can go pretty deep into the formatting options by clicking on the Tag Specific Options button:
Formatting the document or selection is a great way to make your code more readable. Enjoy!
I ran into this the other day (http://github.com/indeyets/syck/blob/master/COPYING) and thought I would share
Copyright (c) 2003 why the lucky stiff
[BSD license text deleted to save space]
D&R (Death and Repudiation) License
This software may not be used directly by any living being. ANY use of this
software (even perfectly legitimate and non-commercial uses) until after death
is explicitly restricted. Any living being using (or attempting to use) this software
will be punished to the fullest extent of the law.
For your protection, corpses will not be punished. We respectfully request
that you submit your uses (revisions, uses, distributions, uses, etc.) to
your children, who may vicariously perform these uses on your behalf. If
you use this software and you are found to be not dead, you will be punished
to the fullest extent of the law.
If you are found to be a ghost or angel, you will be punished to the fullest
extent of the law.
After your following the terms of this license, the author has vowed to repudiate
your claim, meaning that the validity of this contract will no longer be recognized.
This license will be unexpectedly revoked (at a time which is designated to be
most inconvenient) and involved heirs will be punished to the fullest extent
of the law.
Furthermore, if any parties (related or non-related) escape the punishments
outlined herein, they will be severely punished to the fullest extent of a new
revised law that (1) expands the statement "fullest extent of the law" to encompass
an infinite duration of infinite punishments and (2) exacts said punishments
upon all parties (related or non-related).
Keyboard: F5; CTRL + F5Menu: Debug -> Start Debugging; Debug -> Start Without DebuggingCommand: Debug.Start; Debug.StartWithoutDebuggingVersions: 2008,2010Published: 11/1/2010Code: vstipDebug0037
While researching this one I came across a LOT of misinformation concerning what is actually happening here. There seems to be a great deal of confusion as to what is actually happening when you use Start Debugging (F5) versus Start Without Debugging (CTRL + F5):
Starting With Debugging
Let's start with the basics: When you press F5 (Start Debugging) in Visual Studio it launches your application, attaches the Debugger, and let's you do all the "normal" things you would expect:
According to the documentation (http://msdn.microsoft.com/en-us/library/k0k771bt(v=VS.100).aspx) here is what the Debugger does:
"The Visual Studio debugger is a powerful tool that allows you to observe the run-time behavior of your program and locate logic errors. The debugger works with all Visual Studio programming languages and their associated libraries. With the debugger, you can break, or suspend, execution of your program to examine your code, evaluate and edit variables in your program, view registers, see the instructions created from your source code, and view the memory space used by your application."
The Debugger: Release Builds
One popular misconception is the Debugger doesn't come into play for Release builds. This isn't true. Set a Breakpoint in some code for a Release build and then press F5 to see if is stops there:
Of course it does! The Debugger is attached! That is what is happening. Now, there are some things that aren't happening as well. For example, you can't use the System.Diagnostics.Debug class methods to send messages to the Output window since the compiler strips them out for Release builds:
Start Without Debugging
This is exactly what it sounds like. It starts the application WITHOUT THE DEBUGGER ATTACHED. That's it! Nothing else. It just doesn't attach the Debugger. Otherwise everything else is the same. So, the practical implications of this are obvious: Without the Debugger attached when the application runs it will not hit Breakpoints, emit Debug messages, etc. So now let's deal with the biggest myth about Start Without Debugging.
Myth: Start Without Debugging Creates a Release Build
Nope. It uses the build you are currently on. So if you are using a Debug build and you press CTRL + F5 then it will run that Debug build. The easiest way to test this is to use conditional compilation to see if you are using a Debug build:
In this example, the Console statement will run but the Debug statement will NOT run because the Debugger is not attached. So I will get this output:
And, if I attach the debugger after pressing CTRL + F5, to this process:
Then this is what I get:
The Debug messages haven't been stripped out because I'm using a Debug build of the application.
Okay, so the obvious question is "Why?". I mean, why would they give us this option? Well the most obvious answer is so we can run the application without having to hassle with disabling breakpoints, etc. to do a quick "Smoke Test" and see if it runs. There may be other reasons you have for wanting to run without the Debugger attached as well. So now you have a better idea of the difference between Start With and Start Without Debugging. Go forth and debug away!
Keyboard: CTRL + G Menu: Edit -> Go ToCommand: Edit.GoToVersions: 2008,2010Published: 3/8/2010Code: vstipEdit0026
You can go to any line number in your code by simply pressing CTRL + G. You will get this dialog:
Just type in your desired line number and click OK. The Cursor will move to the line number you typed.
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.
Visual Studio 2013 has another great new feature: enhanced scroll bar functionality. The new scroll bar will show cursor location, breakpoints, and much more! Let’s take a look.
Before we begin I want to address where some of the new features in VS2013 are coming from. In Visual Studio 2013 many of the new features we put into the product were actually introduced via the Productivity Power Tools for Visual Studio 2012. This is an ongoing trend and you will see that many of the new features from future versions will come directly from the Power Tools. If you are still on 2012 you can get a lot of the newest functionality by installing the Visual Studio 2012 Power Tools which can be found here:
To really get a handle on the new scroll bar functionality the first thing you should do is Right Click on the vertical scroll bar and choose Scroll Bar Options:
You will see several settings that can be modified:
(NOTE: You can also get to this area by going to Tools | Options | Text Editor | All Languages | Scroll Bars)
The first two options are pretty self-explanatory they will allow you to show or hide the scroll bars. For the most part you will leave these checked unless you have some special reason not to have them visible.
The Display area allows you to turn on annotations that will show special items throughout the entire document within the scroll bar. This allows you, at a glance, to see where things like breakpoints and bookmarks are. We will look at these in the order you are most likely to encounter them but here is an example of the vertical scroll bar with annotations in it:
The first annotation you will most likely encounter is the caret position indicator. It simply shows the current position of the cursor with a blue line in the scroll bar.
If you missed my blog post a couple of years ago on tracking changes in the editor, this is a good time to read it. You can find the post here:
The Show Changes option simply shows the changes within it so you can see modifications at a glance for the entire document.
This options is fairly broad and covers several types of marks that can appear in code. Most notably this will show breakpoints:
Additionally, this will also show things like Bookmarks:
The final indicator is arguably one of the most important. It shows any syntax errors the editor is aware of:
This let’s you quickly see where there are errors that need to be fixed before you compile your code.
There are two behavior options for the vertical scroll bar: bar mode and map mode. So far everything we have seen is the traditional bar mode for the scroll bar. Now we will switch to map mode:
Map mode essentially turns your vertical scroll bar from this:
Map mode is miniature look at your document so you can quickly get a feel for your code. There are four options for source overview when using map mode. I’ll show examples of the four views below. Of these the Off setting will be the most confusing until you see the Preview Tooltip in action so be patient.
Regardless of which map mode view you use there is also an option to have the Preview Tooltip. Simply put your mouse pointer over any part of the vertical scroll bar and you will get a preview of the code at that position in the document:
All annotations previously mentioned also show up in map mode:
You basically have two options when you want to go to a specific location on the scroll bar. Let’s examine both ways.
As long as you are in map mode:
You can simply LEFT CLICK any area on the scroll bar and you will jump to that location:
For this reason, I suggest, even if you don’t want the map, that you at least use map mode set to Off to get this functionality so you can quickly move around using the scroll bar:
Now that you have a solid base level of knowledge for this feature there is one more important item I want to show you: Scroll Here. If you find any place that is interesting to you in the vertical scroll bar and want to quickly go to that location you can simply Right Click the location and choose Scroll Here:
The new location will come into view so you can begin looking at the code:
The enhanced vertical scroll bar is a great tool for developers to quickly see places of interest and to examine those locations. Try this feature out and see if you like it as much as I do. :)
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...
This is one change to Visual Studio that I’m not a fan of and I still continue to see a ton of posts on this change so thought I would share here as well.
I always try to give credit where credit is due and I believe the earliest mention of this fix is by Richard Banks in his post 6\1\2012 here: http://www.richard-banks.org/2012/06/how-to-prevent-visual-studio-2012-all.html
Okay so you really, really don’t like the Uppercase menu in VS2012 because you feel like it is shouting at you:
You would rather go back to mixed case for your menu:
Not a problem! Below are ways you can fix this feature in VS2013.
WARNING: Making changes to the registry can cause unexpected results so do any changes at your own risk!
NOTE: Watch your spelling if you are typing this manually.
If you like to “simplify” this a bit you can use PowerShell to run a nice script to make this happen. However, if you haven’t used PowerShell before this may not be faster for you.
Set-ItemProperty -Path HKCU:\Software\Microsoft\VisualStudio\12.0\General -Name
SuppressUppercaseConversion -Type DWord -Value 1
Restart Visual Studio and you are good to go.
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 :)
Keyboard: CTRL + SHIFT + U (upper); CTRL + U (lower)Menu: Edit -> Advanced -> Make Uppercase; Edit -> Advanced -> Make LowercaseCommand: Edit.MakeUppercase; Edit.MakeLowercaseVersions: 2008,2010Published: 4/10/2010Code: vstipEdit0044
Download the seriously cool Tip of the Day Extension to get the daily tips delivered to your Start Page!
Okay, so let's say you have some text (a variable, maybe?)
and you need to do some case-changing action on it. Plus, there is a crazy guy holding several people hostage and threatening to dip them in boiling chocolate unless you do it fast. What do you do? No Problem! You just select the word and press CTRL + SHIFT + U to make it uppercase
or if the evil guy isn't satisfied you can always make it lowercase by pressing CTRL + U
And now you have saved the day!