Blog - Title

Visual Studio 2012 & 2013 Current Builds

  • The Ultimate Visual Studio Tips and Tricks Blog

    TODO Comments in the Task List

    • 21 Comments

    Versions:  2008,2010
    Published:  6/7/2010
    Code:  vstipTool0029

     

    Ever been writing some code and you want to leave a reminder to yourself to do something on a particular line or area?  Did you know about the "to do" comment feature?  It seriously rocks if you have never used it AND, because it goes in the source code, everyone can have access to the information when you do you check-in!

     

    So here's how it works:  In VB you just put any comment in that begins with the letters "todo" (case doesn't matter):

    image

     

    In C#, it's pretty much the same thing (again, case doesn't matter):

    image

     

    C++ requires that the “TODO” be in upper-case or it will not show up in the Task List:

    clip_image002 

     

     

    In C++ for VS2010 you have to explicitly turn this feature on.  Go to Tools | Options | Text Editor | C/C++ | Formatting | Miscellaneous and change Enumerate Comment Tasks to true:

    clip_image004 

     

     

    Regardless which language you use the result is a nice entry in your Task List:

    clip_image006 

     

    NOTE:  In order to see these items, you have to click the drop-down list in the Task List and choose Comments as shown here.

  • The Ultimate Visual Studio Tips and Tricks Blog

    Visual Studio 2012 New Features: Improving User Stories and Requirements with PowerPoint Storyboarding

    • 2 Comments

    For Visual Studio Premium and Ultimate users there is a great new add-in for PowerPoint that can really help you called the PowerPoint Storyboarding add-in.  Using this feature you can quickly draft an interface design and get stakeholder feedback.  Plus, since it’s PowerPoint, even stakeholders can change elements easily to show you what they really want.  Let me show you how this works.

     

    Getting Started

    To get started just go to the Microsoft Visual Studio 2012 program folder and select PowerPoint Storyboarding:

    PowerPoint Storyboarding

     

    This will open up PowerPoint, give you a blank slide, and take you to the Storyboarding tab:

    image

     

    It will also show the storyboard shapes to the right which are searchable via the search box (CTRL + G):

    image

     

    (NOTE:  You can download more shapes by going to http://visualstudiogallery.msdn.microsoft.com/site/search?f%5B0%5D.Type=RootCategory&f%5B0%5D.Value=StoryboardShapes&f%5B0%5D.Text=Storyboard%20Shapes)

     

    From here you typically start with a background from the storyboard shapes:

    image

     

    For this example, I am developing a SharePoint solution so want a SharePoint background:

    image

     

    I can edit existing elements and/or add new storyboard shapes:

    image

     

    I can right-click on any item and add hyperlinks that the user can click on to take them to another “screen” (slide) for more interaction:

    image

     

    If you find yourself using a customized set of shapes frequently just select the shapes and add them to your storyboard shapes:

    image

    image

     

    One of the coolest features is the ability to quickly update your custom shapes while you are working on them as well as export them for other team members to use:

    image

     

    As you gain experience with the tool, here is an example of what you can accomplish:

    image

     

    If you are using Team Foundation Server (you ARE using TFS aren’t you?) then you can also link your storyboard to one or more requirements/user stories with the Storyboard Links button:

    image

     

    The only caveat is you have to store the ppt file in a location that is accessible to others or it will give you this message:

    image

     

    I prefer to use the project portal created by TFS to store my storyboards personally.  Once you have saved the file to a shared location then you can link it to work items.  When you first open the Linked Work Items dialog it will show the collection you are connected to in the title bar:

    image

     

    You can click Link To to link items in the current collection and/or Connect to go to another collection and then run queries for the items you are interested in selecting:

    image

     

    From now on you can see the work items that are associated with with the storyboard and be able to trace the work you are doing back to some requirement/user story/task/etc…

     

    There you have it!  Give the new storyboarding features a try yourself.  If you want to see the docs on this feature, I would check out these two links:

    http://msdn.microsoft.com/en-us/library/hh409276(VS.110).aspx

    http://msdn.microsoft.com/en-us/library/hh301773(VS.110).aspx

    Normally our documentation is *cough* less than optimal but the two items above are actually pretty good.

  • The Ultimate Visual Studio Tips and Tricks Blog

    GREP and SED with PowerShell

    • 10 Comments

     

    So...I like GREP and SED from my old UNIX days and am VERY happy to see that PowerShell can do the same type of functionality with a lot more power in most cases.  I though some of you might like some really simple examples of how to take a text file and do GREP-ish and SED-ish actions.

     

    GREP-ish

    cat somefile.txt | where { $_ -match "expression"}

     

    The command above will search each line of "somefile.txt" to see if it contains the regular expression "expression" and return the entire line if there is a match.

     

     

     

    SED-ish

     

    cat somefile.txt | %{$_ -replace "expression","replace"}

     

    The command above will search each line of "somefile.txt" for the regular expression "expression" and replace it with the string "replace".

     

     

     

    EXAMPLE:

    ==============DATA.TXT==============

    Mary had a little lamb,

    It's fleece was white as snow,

    But the lamb made Mary mad,

    So she ate it.

    =================================

     

    GREP-ish

    cat DATA.TXT | where { $_ -match "Mary"}

     

    returns the following:

    Mary had a little lamb,

    But the lamb made Mary mad,

     

     

    SED-ish

    cat DATA.TXT | % { $_ -replace "Mary","Susan" }

     

    returns the following:

    Susan had a little lamb,

    It's fleece was white as snow,

    But the lamb made Susan mad,

    So she ate it.

     

    ================ Edit 7/14 ==================== 

    A question came up the the other day about putting these results into another text file.  Using redirection this is quite easy.  Here is how it is done:

     

    cat DATA.TXT | % { $_ -replace "Mary","Susan" } > newfile.txt

     

    ============================================

    enjoy :)

     

  • The Ultimate Visual Studio Tips and Tricks Blog

    Visual Studio 2012 New Features: Solution Explorer

    • 8 Comments

    I love the title of this one because I’m sure someone will read this and wonder why I think Solution Explorer is a “new” feature.  I mean, haven’t we had this sucker for a billion years?  Aren’t there cave drawings in France about this feature?  So why is it “new”?  Let me show you!

     

    Search Solution Explorer (CTRL + ;)

    First and foremost, you can now search Solution Explorer!  I’ve been wanting a feature like this since before Solution Explorer was even invented back in my VB 3 days (about 19 years ago).  Here is what things looked like back then:

    image

     

    And from then until Visual Studio 2010 we STILL couldn’t search items:

    image

     

    But now you can!  Just type in any search term into the Search Solution Explorer textbox:

    image

     

    And it will find anything that contains the search term in it:

    image

     

    You can filter the search to choose how broad the search goes by clicking on the drop down arrow to the far right of the Search Solution Explorer textbox:

    (NOTE: searching within file contents doesn’t mean what you think it means.  See the section “More Than Physical” for information)

    image

     

    One other cool feature is you can have Solution Explorer only show you the currently open files by clicking the drop down button just to the right of the Home button:

    image

     

     

    More Than Physical

    In the past, Solution Explorer was relegated to only showing physical elements or those things that help contain / organize those elements (i.e. solution folders).  That’s out the window, too.  Now the experience doesn’t stop at the physical level but extends to logical elements as well:

    image

     

    Which makes searching even more awesome:

    image

     

    If you are using the Preview Tab then clicking on any item in Solution Explorer will go to the file and highlight code if applicable BUT you can’t double click the logical item to open the file for some reason and instead have to double click the filename to open it.

     

     

    Navigation

    Navigation is much improved as well. 

     

    Browser-Like Movement

    After a doing a search, like the one shown above, you can click the Home button:

    image

     

    And Solution Explorer will go back to “normal”:

    image

     

    Clicking the Back button:

    image

     

    Takes me back to the search I just did:

    image

     

    Here is the weird part:  If I reuse the search box and type another search right away it doesn’t remember the previous search I did and I can’t go back; BUT if I click Home between searches then it remembers all my old searches.  I’ve tested this up to 12 entries and it works fine as long as you remember to click Home between searches.

     

    Sync with Active Document

    Occasionally you may be looking at a file but Solution Explorer isn’t on that file.  When this happens a button appears that allows you to sync Solution Explorer with the document you are currently in so you can see where it is in the project structure.

    image

     

    Right Click Experience

    The right click experience is, to say the least, incredible!  Depending on what you select the context menu changes appropriately.  So if I right click a code file this is what I get:

    image

     

    But if I right click a class this is what I get:

    image

     

    And this is the context menu for a method:

    image

     

    Each option changes the view in Solution Explorer to better examine relationships.  The bottom line:  make sure to check out your context menus to change the elements you are viewing in Solution Explorer.

     

     

    New Solution Explorer View

    There used to be a button for creating a new instance of Solution Explorer which was excellent for multi-monitor viewing of code:

    image

     

    The button is gone now (which is a mistake in my opinion) and you can no longer get an entire copy of Solution Explorer in a new window BUT you can get a copy of any project or file in a new Solution Explorer window which is what I have done in the example above.  Just right click any project/file and choose New Solution Explorer View:

    image

     

     

    Team Foundation Server

    If you are using TFS then you can filter Solution Explorer to show you files with Pending Changes:

    image

     

    And there you have it!  As you can see there are quite a few changes in the new, improved Solution Explorer so go explore!

  • The Ultimate Visual Studio Tips and Tricks Blog

    World of Warcraft Install on Vista

    • 82 Comments

    Okay, so I bit the bullet and installed WOW on Vista last night.  I am going to install the patches tonight and see how it works.  If anyone has had issues, lemme know.  BTW, feel free to catch up with me on Eredar (70 NE Priest -- SQLVarChar).  I don't play as often as I used to but still try to get in  a couple of instance runs on weekends.

    Z

  • The Ultimate Visual Studio Tips and Tricks Blog

    Cut or Delete the Current Line

    • 9 Comments

    Keyboard:  CTRL + L (cut text); SHIFT + DEL(cut text and carriage return); CTRL + X(cut text and carriage return); CTRL + SHIFT + L (delete)
    Command:  Edit.LineCut; Edit.Cut; Edit.Cut; Edit.LineDelete
    Versions:  2008,2010
    Published:  4/4/2010
    Code:  vstipEdit0038

     

    You can quickly and easily do a cut operation by doing the following:

    1. Place your cursor on any line:
      image
    2. Do one of the following commands:
      1. CTRL + L to cut the text only
      2. SHIFT + DEL or CTRL + X to cut the line and the carriage return at the end of the line

    If you want to DELETE the line instead you can use CTRL + SHIFT + L

  • The Ultimate Visual Studio Tips and Tricks Blog

    AJAX fun with the dreaded 'sys is undefined' error

    • 27 Comments

    If you have started to play with AJAX then you have most likely come across the dreaded 'sys is undefined' error.  I found numerous articles on how to get this working but the best ones all point to making sure you have the correct entries in your web.config.   So to summarize what I have read:

    1)  Go to C:\Program Files\Microsoft ASP.NET\ASP.NET 2.0 AJAX Extensions\{your version of AJAX}

    2)  Open the sample web.config file and make sure you have the same entries in your web.config

    3)  If you don't then copy and paste is your friend :)

    4)  See if the app works now

     Here are a couple of articles to assist if you are still having issues:

    Chris Riccio's blog   http://weblogs.asp.net/chrisri/archive/2007/02/02/demystifying-sys-is-undefined.aspx

    Lorin Thwaits's blog  http://geekswithblogs.net/lorint/archive/2007/03/28/110161.aspx

     

  • The Ultimate Visual Studio Tips and Tricks Blog

    Code Metrics – Maintainability Index

    • 0 Comments

    SKU: Premium, Ultimate

    Versions: 2008, 2010

    Code: vstipTool0134

     

    At long last it is time to look at the final metric from the code metrics (see vstipTool0129, “Code Metrics - Calculating Metrics”): maintainability index. As with the other metrics it is best to start with some definitions. First, from the MSDN main documentation:

    “[Maintainability Index c]alculates an index value between 0 and 100 that represents the relative ease of maintaining the code. A high value means better maintainability. Color coded ratings can be used to quickly identify trouble spots in your code. A green rating is between 20 and 100 and indicates that the code has good maintainability. A yellow rating is between 10 and 19 and indicates that the code is moderately maintainable. A red rating is a rating between 0 and 9 and indicates low maintainability.”

    http://msdn.microsoft.com/en-us/library/bb385914.aspx

    (emphasis added)

     

    Unlike other metrics, there is virtually no ambiguity to reading this value. David Kean on the code analysis team blog provides a view into the values, icons, and colors you could see:

    image

    http://blogs.msdn.com/b/codeanalysis/archive/2007/10/03/new-for-visual-studio-2008-code-metrics.aspx

     

     

    Using this information you can easily see areas of code that may need attention. But what does this look like when you actually use it? I took some sample code and created extreme conditions to show how this looks in actual use. If we just look at maintainability index everything looks fine:

    image

     

    Be careful! This is not the whole picture. Maintainability index is actually a calculation using three metrics. Two of the metrics used are lines of code (see vstipTool0130, “Code Metrics - Lines of Code”) and cyclomatic complexity (see vstipTool0131, “Code Metrics - Cyclomatic Complexity”). Without looking at these you will miss something. Let’s add them to our code metrics:

    image

     

    We have a problem. The lines of code don’t’ really seem excessive but the cyclomatic complexity is very, very high and that is a red flag. We need to dig into the hierarchy to see what is going on. I’ll go two levels down:

    image

     

    Now we see a major problem. Just looking at the maintainability index alone wouldn’t have revealed the issue at a high level but paying attention to the cyclomatic complexity definitely revealed a code smell (http://en.wikipedia.org/wiki/Code_smell) that needed further investigation. At this point we would take action to correct for high cyclomatic complexity.

    The moral of this story is to pay attention to your metrics. At this point you should be well armed to use maintainability index for your code. If you want to get into the details then read on…

     

     

    Digging Deeper

    When dealing with metrics the details can be important. It’s good to see how they are calculated. Fortunately, the Code Analysis Team blog has provided the calculation used for maintainability index:

    Maintainability Index = MAX(0,(171 - 5.2 * log(Halstead Volume) - 0.23 * (Cyclomatic Complexity) - 16.2 * log(Lines of Code))*100 / 171)

    http://blogs.msdn.com/b/codeanalysis/archive/2007/11/20/maintainability-index-range-and-meaning.aspx

     

    This is just one of many ways to calculate maintainability index (http://www.virtualmachinery.com/sidebar4.htm) and there are calculation variants that take into account additional items such as comments. I’ve already covered lines of code (see vstipTool0130, “Code Metrics - Lines of Code”) and cyclomatic complexity (see vstipTool0131, “Code Metrics - Cyclomatic Complexity”). Halstead Volume, on the other hand, is new to our discussions.

     

    The Halstead metrics where created in 1977 by Maurice Halstead to create empirical methods to measure software development efforts. He sought to identify and measure software properties as well as show relationships between them. (http://en.wikipedia.org/wiki/Halstead_complexity_measures) You can find a great description of how to calculate Halstead metrics at http://www.virtualmachinery.com/sidebar2.htm.

     

    Halstead Volume can be defined as “[…] the size of the implementation of an algorithm. The computation […] is based on the number of operations performed and operands handled in the algorithm. Therefore [it] is less sensitive to code layout than the lines-of-code measures.”

    http://www.verifysoft.com/en_halstead_metrics.html

     

     

    Code Analysis

    When using code analysis, the Extended Design Guideline rule set contains a maintainability area:

    image

     

    Inside the maintainability area is a rule for maintainability index:

    image

     

    This rule is triggered when the maintainability index is low. You can learn more about the rule here:

    http://msdn.microsoft.com/en-us/library/bb386043.aspx

    Unfortunately, the documentation doesn’t talk about the thresholds set for this rule but I ran my own experiments and found that at 19 or below this rule will issue a warning by default.

  • The Ultimate Visual Studio Tips and Tricks Blog

    How to Turn Off Automatic IntelliSense

    • 5 Comments

    Menu:  Tools -> Options -> Text Editor -> All Languages [or specific language] -> General -> Statement completion
    Versions:  2008,2010
    Published:  5/1/2010
    Code:  vstipEdit0054

     

    image

    So maybe IntelliSense isn't for everyone.  It can sometimes annoy people when it automatically pops up.  You can disable automatic IntelliSense and still have it come up anytime you want with CTRL + J.

  • The Ultimate Visual Studio Tips and Tricks Blog

    How to Convert Tabs to Spaces and Vice Versa

    • 10 Comments

    Menu:  Edit -> Advanced -> Tabify Selected Lines; Edit -> Advanced -> Untabify Selected Lines
    Command:  Edit.TabifySelectedLines; Edit.UntabifySelectedLines;Edit.ConvertTabsToSpaces;Edit.ConvertSpacesToTabs
    Versions:  2008,2010
    Published:  3/14/2010
    Code:  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):

    image

     

    Now go to Edit -> Advanced -> Tabify Selected Lines:

    image

     

    And you should get the leading spaces converted to tabs:

    image

     

    Obviously, to change leading tabs to spaces you would use Untabify Selected Lines:

    image

     

     

    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):

    image

     

    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:

    image

     

    And now you know how to convert tabs to spaces and spaces to tabs.  Have fun! 

Page 2 of 135 (1,345 items) 12345»