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).
The Visual Studio 2012 Virtual Launch Event is coming September 12! Make sure to add this free event to your calendar so you can attend. Just click the Add to Calendar link above to make sure you don’t miss out on some great stuff!
On August 15th we announced the availability of, both, Visual Studio 2012 and Windows 8.
You can find out more on our Visual Studio from Soma’s blog post here:
For those wanting to get their hands on the goods now here is an excerpt from the post:
For Windows 8, you can get details on the release here:
Here is the relevant part that deals with how to get your hands on the bits:
Depending on what Microsoft programs you or your organization might be part of, there are a few ways to get the RTM version of Windows 8. If you have an MSDN Subscription or a TechNet Professional Subscription, the RTM is available today. For info on other programs see the Windows 8 has reached the RTM milestone post on Windows Team blog.
If you are not part of one of these programs, don’t worry, we’re also offering a 90-day evaluation of the Windows 8 Enterprise edition for developers. This is available now from the Windows Dev Center download page along with Visual Studio Express 2012, Windows 8 design assets, code samples, and all the related tools and SDK’s you need to build apps.
If you use the evaluation version, we recommend installing it on separate drive or partition or in a VM. This way you’ll be able to upgrade from your original OS to the Windows 8 RTM when it becomes available in October. If you don’t, then you’ll need to reinstall from scratch when you decide to move to the full version. Make sure you read all the details on the download page.
Make sure to get your hands on these if you haven’t already and keep looking out for new series on my blog on the new Visual Studio!
I'll be on vacation until Aug 6th so there will be no posts until the week after I get back. We will resume our regularly scheduled posts at that point :)
In my travels across the country, with my fellow Evangelist, Clint Edmonson, talking about Visual Studio we often come across great stories to tell. One of our favorite true stories is of a customer that had a web application running very slow. We ran code metrics against it and, sure enough, the Page_Load event had 9,000 lines of code in it.
Naturally we were curious so we opened it up to see that it was basically the same if statement copied over and over. Apparently they needed to find out who was coming into the website in order to show customized content and the solution they came up with was this massive set of statements.
For better or worse we have all had code that gets copied throughout our solutions. Until now there was no tool to tell us there were copies and, instead, we had to rely on other metrics to hopefully reveal any code smells that lead us to duplicates. Now, however, we have the new Code Clone Detection (aka Code Clone Analysis) feature.
According to the documentation:
“Code clones are separate fragments of code that are very similar. They are a common phenomenon in an application that has been under development for some time. Clones make it hard to change your application because you have to find and update more than one fragment. Visual Studio can help you find code clones so that you can refactor them.”
You can find clones of specific code by selecting the segment you are interested then right click on the selection to choose Find Matching Clones in Solution from the context menu:
Visual Studio will search for code clones and produce the result in the new Code Clone Search Results window:
The original line of code is put in a group on its own and then all the matches are put into a different group. You can expand the groups to see the specific locations of the matches:
Also, you can double click on any entry in the list to go to the selection in your code file:
Besides looking for specific clones you can also look for code clones for the entire solution. To use this feature go to Analyze | Analyze Solution for Code Clones:
This creates a result set for the entire solution:
By default it groups and sorts the results by the strength of the match. Exact matches come first then those matches that may be close but not exact come next and so on. The terms you may see are Exact, Strong, Medium, and Weak.
Once you have the result set, there are a couple of ways you can compare them against each other.
If you have a comparison tool configured you can Right-click on any item and select Compare from the shortcut menu:
You would know if you have this feature available by going to Tools | Options | Source Control | Team Foundation Server and click on Configure User Tools.
If you don’t have a comparison tool you can do manual comparisons between two entries in the list. If the clones are in different files then you can just double-click each entry and it will open the file as well as highlight the entry that is duplicated as mentioned earlier.
You are probably curious as to what is found by this tool. The heuristics for finding clones will find duplicates even if the following changes have happened:
· Renamed identifiers
· Insert and delete statements added
· Rearranged statements
There are some rules for what is not found as well. I have taken this list from the documentation pretty much verbatim.
· Type declarations are not compared. For example, if you have two classes with very similar sets of field declarations, they will not be reported as clones. Only statements in methods and property definitions are compared.
· Analyze Solution for Code Clones will not find clones that are less than 10 statements long. However, you can apply Find matching clones in solution to shorter fragments.
· Fragments with more than 40% changed tokens.
· If a project contains a .codeclonesettings file, code elements that are defined in that project will not be searched if they are named in the Exclusions section of the .codeclonesettings file.
· Some kinds of generated code are excluded:
· *.designer.cs, *.designer.vb
· InitializeComponent methods
A settings file is available to configure this feature at the project level. Currently we have only announced the ability to do exclusions in the file but there will most likely be other elements that are added later on. The file is just XML with a .CODECLONESETTINGS extension. The only requirement for use is that the file exists in the top level directory of the project.
The base elements consist of a CodeCloneSettings element with an Exclusions child:
Within the Exclusions element you can have the following children:
This element is used to indicate files that should be excluded from analysis. Path names can be absolute or relative and you can use wildcards as well. So, for example, to ignore all the C# text template files that have been put in their own directory (called MyTextTemplates) you might have the following:
You can also exclude namespaces, types, and functions. Just like files these items can use absolute names or names with wildcards in them. Here is an example of what it might look like:
In the Tailspin Toys sample there is some generated code in the TailSpin.SimpleSqlRepository project that is the bulk of the duplications:
When I run code analysis, this is the result:
Code clone analysis doesn’t automatically know to ignore text templates so I would create an XML file called TailSpinRepository.codeclonesettings and insert an entry like this:
Now if I run clone analysis again here is what I get:
As you can see the results are significantly less than the first time the analysis ran. It’s common to create several exclusions in different projects to weed out noise in the analysis results.
Code Clone Detection is a great new tool to add to your arsenal for improving code quality. Combined with Code Analysis and Code Metrics, this will help quickly find potential issues.
In the past, finding things deep in the IDE has been a challenge. Visual Studio 2012 introduces search abilities at virtually every level of the product. Perhaps the biggest change is the introduction of Quick Launch (CTRL + Q) which specifically addresses how to dig inside Visual Studio to find features you need. Let’s take a look.
You can find Quick Launch in the upper right corner of the IDE:
The most basic scenario for using Quick Launch is finding an item that you have forgotten (or don’t know) the location of. Let’s say you are interested in something deep in the menu system like viewing your white space. You know what it’s called but can’t remember where it is at. Just press CTRL + Q and enter the word white:
All searches are contains operations so the results will show anything that has the word white anywhere in it. The results are grouped into categories and you simply either select the item from the list using your keyboard, mouse or, if there is a keyboard shortcut listed, take advantage of the shortcut. In this case, you could press CTRL+R, CTRL+W to show the white space and then go on with your work.
There are four categories that your results will fall into when using Quick Launch. Let’s take a look at each of these categories.
Pretty self-explanatory; this category is at the top of the dialog and will show up to the last 5 most recent items that match the current search criteria. Pay attention to the last part of that sentence. Only if it (a) was used by you before from this dialog and (b) matches the current search criteria will an item show up in the MRU list.
You can search just your Most Recently Used items by preceding any search with @MRU (case doesn’t matter):
This obviously refers to menu items. So if I type in option for a search term the menus section shows menu items that contain the term:
You can filter results to show only commands by preceding any search with @MENU (case doesn’t matter):
The Options category does what you might expect--it shows items that can be found by going to Tools | Options on the Menu Bar:
As with the other categories, you can filter your search to just options by preceding any search with @OPT:
The only real limitation to keep in mind is this type of search doesn’t go beyond two levels deep and the description. For example, if I type the word document here is the result in the options category:
Which corresponds to Tools | Options | Environment | Documents (and Tools | Options | Text Editor | C# as well):
Notice the search went two levels deep (Environment | Documents) but didn’t list out the items to the right that contain our search term in it.
This category is somewhat interesting. It searches file names and paths of open documents for the search criteria but not the text inside the files themselves. There are plenty of tools that can be used to search inside files and the context for Quick Launch is at a higher level. This feature is useful for finding a file when you have several files open:
As with the other categories it, too, can be filtered to search just show open files by putting @DOC at the front of your search:
You can selectively turn off categories you don’t want to see by typing quick in Quick Launch and selecting the result in Options:
Note: For the old school folks this can be found at Tools | Options | Environment | Quick Launch
Then deselect the special search providers you don’t want:
The next time you run a search it will not show the categories you have turned off in your result set.
As you may have noticed when playing with this feature it doesn’t show all the items in the initial results but does have a number indicating how many items it found:
Clearly not all 123 items in the Options are being shown but notice the message at the bottom of the list. If the results are too large to show we can just press CTRL + Q to show them all. Additionally, if you continue to press CTRL + Q it will cycle through showing all items in all categories and filtering by each category:
By default the search term you use is not persisted between search sessions. So if you search on something:
Then place move the cursor outside the Quick Launch area and go back the search term has been cleared from the area:
Personally, this is very annoying to me and thankfully the VS team has a fix. Just go to the Quick Launch in Options area:
Then select Show Search Results From Previous Search When Quick Launch Is Activated option:
The next time you run a search, leave the Quick Launch area, and come back it will retain the search term last used and show you the search results as well.
If for some insane reason you don’t like the Quick Launch feature, you can always turn it off by going to Quick Launch in the options:
Then deselecting the Enable Quick Launch option:
This will remove the Quick Launch area from the IDE:
To bring it back just go to Tools | Options | Environment | Quick Launch and select Enable Quick Launch.
I absolutely love this feature! My passion is around helping people be more productive in the IDE and I think Quick Launch is probably one of the biggest steps forward for discovery of VS features that I have ever seen. I’ve been using it for a long time and am at the point now where I can’t imagine not having it. I hope you enjoy it as much as I do.
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!
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:
And from then until Visual Studio 2010 we STILL couldn’t search items:
But now you can! Just type in any search term into the Search Solution Explorer textbox:
And it will find anything that contains the search term in it:
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)
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:
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:
Which makes searching even more awesome:
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 is much improved as well.
After a doing a search, like the one shown above, you can click the Home button:
And Solution Explorer will go back to “normal”:
Clicking the Back button:
Takes me back to the search I just did:
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.
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.
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:
But if I right click a class this is what I get:
And this is the context menu for a method:
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.
There used to be a button for creating a new instance of Solution Explorer which was excellent for multi-monitor viewing of code:
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:
If you are using TFS then you can filter Solution Explorer to show you files with Pending Changes:
And there you have it! As you can see there are quite a few changes in the new, improved Solution Explorer so go explore!
We all explore code and need to move quickly between files when examining code to get familiar with it or debugging or [insert file browsing scenario here]. In prior versions of Visual Studio you had to open a file to look at the contents which often resulted in many open files (tabs) when you were done. The Preview Tab eliminates the need to open files when browsing code. Most likely you’ll first encounter the Preview Tab when you are looking at files with Solution Explorer. When you click on a supported file type, you will see the contents of that file in the new preview tab (to the far right in the tab well):
If you click anywhere inside the file the tab will go from grey to purple to distinguish it from regular (blue) tabs:
Again, the point of the preview tab is to let you view the contents of a file without actually opening up a new tab in the tab well. As you look at different files the preview tab only shows the contents of the file you are currently on. This keeps the environment from getting cluttered with open tabs and allows you to focus on only those files that are interesting to you. Solution Explorer isn’t the only place you can use the preview feature. It turns up in several situations where you might need to look at file content. For example, when using Find in Files (CTRL + SHIFT + F) to locate information you will see the preview tab:
At some point you may decide to promote the preview to an opened tab in the Tab Well so you can do additional work on the file or just keep it around for other purposes. There are a few ways you can make this happen.
Probably the least useful and and least likely technique you will use is to click on the tiny Keep Open button on the Preview Tab. It’s not only useless it’s actually kind of annoying for some reason I can’t identify:
The most likely approach is you will just double click the file in Solution Explorer or whatever results dialog you happen to be in.
With the cursor inside the file (the tab is purple), just press CTRL + ALT + HOME to open a tab for the file you are currently viewing.
While previewing a file, if you make any change to the file it will automatically be promoted to an open tab so that you can make additional changes and do any other actions you need to perform.
Another button is useless and a waste of space on the Solution Explorer toolbar is the Preview Selected Items button. You can click it to preview the current file and its only use that I can find is if you turn off single clicking a file to preview it (see below). Also the tooltip would lead you to believe that you can select multiple files and preview them. Nope. Doesn’t work. Don’t waste your time with this button.
To see the options you have for using the preview feature, just type preview in Quick Launch (CTRL + Q) and click Environment -> Tabs and Windows:
This will take you to Tools | Options | Environment | Tabs and Windows:
To turn off the preview feature (NOT suggested unless you are having performance issues with it) uncheck the Allow New Files to be Opened in the Preview Tab option. Also notice you can decide if a single click open the files in for preview in Solution Explorer and Find dialogs. For Solution Explorer you can use ALT to prevent a file from being previewed when you click on it. While I see the value in using ALT to prevent preview from happening. I haven’t yet found any reason for turning off the single-click option as it, in effect, forces you to use the Preview Selected Items button which is a lot of extra work and kind of defeats the purpose of the feature.
The Preview Tab is one of my top two favorite features in Visual Studio 2012 (the other one being project round-tripping). You definitely want to leverage this feature to make your life easier.
I’ve been seeing a ton of posts lately on this feature so thought I would share here as well. I also like to give credit where credit is due so I did a search and it looks like the earliest mention of this ability 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 If anyone knows of an earlier one done by someone else let me know but this looks like the first mention of it. If I were a betting man I would say he most likely used Process Explorer to make this discovery which is my favorite tool for finding things like this.
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! Let’s see how:
WARNING: Making changes to the registry can cause unexpected results so do any changes at your own risk!
Open the registry editor and go to HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\11.0\General\ (For Windows 8 Desktop Express go to HKCU\Software\Microsoft\WDExpress\11.0\General) //special thanks to msm8bball for the update(For Web Express go to HKEY_CURRENT_USER\Software\Microsoft\VSWDExpress\11.0\General)
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\11.0\General -Name
SuppressUppercaseConversion -Type DWord -Value 1
Restart Visual Studio and enjoy!
Jonah Lehrer the author of “How We Decide” has written an article for the New Yorker showing how people take mental shortcuts to arrive at wrong answers. Most surprisingly was the finding that more intelligent people make this mistake more often than others. You can read the entire article here:
Also, if you haven’t read “How We Decide” and are interested in a nice high-level look at the cognitive decision-making process then you should absolutely read this book:
[Reader Note: It looks like the formatting is cutting off the table on my main blog page. If you click on the link for the full story it will show in full.]
I was talking with a customer the other day that uses Visual Studio Ultimate for many of its developers and just happened to mention the feature packs. I was surprised to discover that he didn’t know much about them so thought I would do a general discussion on them for folks.
NOTE: Some feature packs have a minimum level required to use them and may require higher level SKUs to use them.
According to the documentation: “Microsoft Visual Studio 2010 feature packs let you extend Visual Studio 2010 with capabilities that enhance and complement the existing tools. This release expands the scenarios where you can use Visual Studio 2010 to help you create better software.”
In a nutshell, feature packs allow us to augment Visual Studio with features we couldn’t get in by RTM or to enhance features we have delivered already. They are a great way provide ongoing enhancements to the product in consumable chunks so customers can choose what they want to add.
So what feature packs are available? The VS2012 Feature Packs are still in the works but Jason Zander has revealed that the first packs will be around the following areas:
New capabilities for customizing collection of trace data, including the ability to refine the scope of an IntelliTrace collection to a specific class, a specific ASP.NET page, or a specific function. Better results filtering making it faster to find the data you need as well as improved summary pages for quickly identifying core issues.
As the new feature packs come out I will probably do individual posts on each one.
Here are the Visual Studio 2010 Feature Packs with a description of each one taken directly from http://msdn.microsoft.com/en-us/library/ff636699.aspx
Microsoft Visual Studio 2010 Visualization and Modeling Feature Pack: Overview, prerequisites, and documentation of the visualization and modeling capabilities in this feature pack.
Microsoft Visual Studio 2010 Visualization and Modeling Feature Pack
This feature pack extends the visualization and modeling capabilities in Visual Studio 2010 Ultimate as follows:
Generate dependency graphs for C or C++ code and ASP.NET Web projects.
Create layer diagrams from C or C++ code and validate code dependencies against layer diagrams.
Generate code for UML class diagrams.
Create UML class diagrams from code.
Import UML sequence, class, and use case diagram elements from XMI 2.1 files, which you can export from other tools.
Create links and view links from work items to model elements.
Provide extensibility that lets you write custom code to modify layer diagrams and validate code against them.
For more information about visualizing and modeling code by using Visual Studio 2010 Ultimate, see Modeling the Application.
Microsoft Visual Studio 2010 Feature Pack 2: Overview, prerequisites, and documentation of the extended testing capabilities in this feature pack.
Microsoft Visual Studio 2010 Feature Pack 2
This feature pack extends the testing capabilities in Visual Studio 2010 Ultimate, Visual Studio 2010 Premium and Visual Studio Test Professional 2010 as follows:
Playback tests using the Mozilla Firefox browser. You can use Windows Internet Explorer 7 (or later versions) to record UI actions on a website or a Web-based application and then play back the tests using the Mozilla Firefox browser version 3.5 and 3.6.
Edit coded UI tests using the Coded UI Test Editor. The editor lets you easily modify your coded UI tests. You can locate, view, and edit your test methods, UI actions and their associated controls in the UI control map.
You can create coded UI tests or action recordings for Silverlight 4 applications. Action recordings enable you to fast forward through steps in a manual test.
For more information about testing applications by using Visual Studio 2010, see Testing the Application.
Microsoft Team Foundation Server 2010 and Microsoft Project Server Integration Feature Pack: Overview and documentation about Project Server integration for Team Foundation Server 2010.
http://go.microsoft.com/fwlink/?LinkId=216263Microsoft Team Foundation Server 2010 and Microsoft Project Server Integration Feature Pack
This feature pack lets project managers use Project Server to access up-to-date project status and resource availability across agile and formal software teams who work in Team Foundation. This integration lets data to flow from work items in Team Foundation Server to tasks in enterprise project plans in Project Server. This feature pack lets project managers and software development teams use the tools that they prefer, work at the level of precision that supports their needs, and share information transparently. After the two server products are configured, the synchronization engine maintains scheduling data and resource usage for the configured data in the mapped enterprise project plan and team project.
Microsoft Visual Studio 2010 Load Test Feature Pack: Overview about virtual user license changes included in this feature pack.
Microsoft Visual Studio 2010 Load Test Feature Pack
This feature pack provides Microsoft Visual Studio 2010 Ultimate users who are active MSDN subscribers a license key to generate unlimited virtual users for load testing.
Out-of-the-box, Microsoft Visual Studio Ultimate 2010 restricts you to a maximum of 250 virtual users which can only be used on a local load test run. If your load testing requires more than 250 virtual users, or if you have to use remote machines, you are required to purchase one or more copies of Visual Studio Load Test Virtual User Pack 2010.
Microsoft Visual Studio 2010 Lab Management Feature Pack
This feature pack provides Microsoft Visual Studio 2010 Ultimate with MSDN and Microsoft Visual Studio Test Professional 2010 with MSDN active subscribers the ability to extend the existing Visual Studio Application Lifecycle Management platform to enable an integrated Hyper-V based test lab.
Using a Virtual Lab for Your Application Lifecycle helps you to optimize the use of Microsoft Hyper-V technology to manage and use virtual machines in testing, building, and developing applications in Visual Studio 2010. Visual Studio Lab Management is integrated with System Center Virtual Machine Manager (SCVMM) to enable you manage multiple physical computers that host virtual machines and to manage the storage of virtual machines, virtual machine templates, and other configuration files in SCVMM library servers. Lab Management:
Automates complex build-deploy-test workflows to optimize the build process, decrease risk, and accelerate your time to market
Helps you reduce development and testing costs associated with setup, tear down, and restoration of virtual environments to a known state.
Streamlines the collaboration between development, Quality Assurance, and operations to help organizations achieve higher ROI.
If you haven’t tried out the Feature Packs yet then give them a try today to improve your Visual Studio experience.