Okay so I figured out how to put the .url extension in the advanced indexing options so you can search your favorites only to find out that, hey, you don't have to do all that crap. If you want to search your favs in IE you just type in a part of the...

The other day I had a customer complain about not liking the Light and Dark color themes that come out of the box with VS2012. I’m always up for more choices with color schemes so thought I would make sure you all knew about the options for...

Well, Mike F. reminded me to write this article on 5/29 and I am FINALLY getting around to doing it. Also wanted to give a shout out to Max T. who provided some inspiration on this one as well. For the code, I borrow very heavily from...

The first update for VS2013 came out yesterday and is heavy on bug fixes but not much in the way of new functionality. You can download the latest update from here: http://www.visualstudio.com/downloads/download-visual-studio-vs#d-visual-studio-2013-update...

NOTE: This is an older feature I’ve updated the information for VS2013 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...

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...

Now that Visual Studio 2012 is pretty well baked I thought it would be good to start revisiting some of my favorite features again and introduce new ones. Since project round-tripping is one of my most favorite features I thought we would...

Okay so I figured out how to put the .url extension in the advanced indexing options so you can search your favorites only to find out that, hey, you don't have to do all that crap. If you want to search your favs in IE you just type in a part of the name and it shows up. Talk about a DUH moment. So if you haven't played with it much, I suggest you try out the seriously cool search features in Vista. As for me, I'm off to the Windows Help site to brush up on my searching...

Sometimes it's the simple stuff we forget about. So I present to you the classic Comment and Uncomment Selection. Naturally, you have the Comment and Uncomment buttons:

And, of course, we have the Menu items:

But it's the keyboard shortcuts that really rock! These will, predictably, comment or uncomment lines of code for you. So, let's say you have some code you want commented out. Just select it:

Then press CTRL + K, CTRL + C (in this example):

Voila! It's commented out. Okay, great, but what if you don't want to use the mouse? No problem! Just hold ALT + SHIFT + [UP or DOWN ARROW] to do a vertical selection (NOTE: In VS2008 you have to go right or left one character before you can go up or down for vertical selection):

The other day I had a customer complain about not liking the Light and Dark color themes that come out of the box with VS2012. I’m always up for more choices with color schemes so thought I would make sure you all knew about the options for color schemes. There are actually many, many ways you “could” change your fonts and colors but I’ll show you what I consider to be the top two methods in no particular order.

Visual Studio Color Theme Editor

One of the more popular extensions we created after VS2012 launched was the Color Theme Editor. it comes with pre-set themes as well as the ability to customize your themes any way you see fit. Since it is an extension, you can obtain this feature quickly by following the link to the extension and then clicking the Download link:

Next just click the Open button to install the extension:

Now just follow the on-screen instructions to finish the installation.

Using the Theme Editor

To use the editor you can simply choose a theme by going to Tools | Change Color Theme and selecting a pre-set theme:

Notice that just below Change Color Theme is Customize Colors which allows you to create custom color sets as well. It’s not very intuitive so let me walk you though a little bit of it. First you have to pick an existing theme to copy from and then give the custom theme a name and click the Create button:

Now you will be presented with a dizzying array of options you can modify to create a custom look and feel to your environment:

DANGER: It appears that the Color Theme Editor doesn’t like it when you import settings through the IDE and will use the imported settings instead of the expected settings when changing themes. My advice is to create a custom theme and set it as the current theme then import settings as desired (shown below) so you don’t get messed up themes.

StudioStyles

Getting a Style

Let me walk you though how to use one of these styles. First, you need to find a style you like. I suggest you pick from the All-Time Favourites section. My personal favorite for quite some time has been WekeRoad Ink:

Once you select the style you want then select the proper version of Visual Studio and click the download button:

This will give you a .VSSETTINGS file with just font and color information that you can import into the IDE by going to Tools | Import and Export Settings:

Choose Import Selected Environment Settings then click the Next button:

You should absolutely make sure you BACK UP YOUR CURRENT SETTINGS then click Next:

Use the Browse button to find the .VSSETTINGS file you found then click Next:

Click the Finish button on the current screen:

Choose Close on the last screen and you should have your new color theme:

Undoing Any Changes

You can import your previous settings to change the theme back to any colors you had before. For more information see my previous post here:

Well, Mike F. reminded me to write this article on 5/29 and I am FINALLY getting around to doing it. Also wanted to give a shout out to Max T. who provided some inspiration on this one as well. For the code, I borrow very heavily from the article written by Jean-Paul Mikkers found at:

NOTE: There is an async version of his code that he does as a follow up. I don't use it because I want to remove extra code noise to focus on the act of calling the script itself. If you want to take a stab at the async version (and there are LOTS of good reasons to do so) then you can go here:

1. Now, let's crank out a simple PoweShell script that we are interested in calling. We will call a simple script that takes a couple of numbers and returns the sum of those numbers. This may seem overly simplistic but it is an easy way to demonstrate a complete round-trip between our app and the script without getting bogged down in extra BS that comes with a fancier script. I'll call the script AddItUp.ps1 and it is included in the source code download, just put it anywhere you can get to easily. Feel free to dig into the guts of it later on but for now just assume it does what we need it to do.

Here is the code for the script if you just want to make your own real quick:

2. Test the script by opening PowerShell and navigating to the directory where it is and typing what you see in the graphic, you should get the expected result.

3. Okay! We have a script that works but now what? Well we have to call that puppy from our code so let's create a project and get ready to make our magic happen. Crank out a new Windows App for us to use. Call the Project CallMeCS or CallMeVB depending on your language.

4. For the interface, just gimme a button and a label. Resize the form a bit so we don't have wasted space. Real simple stuff...

5. Double-click on the button to go into our code.

C#:

VB:

6. Now we need to add an assembly that is one of a set we got with our install of PowerShell. You can find these assemblies at C:\Program Files\Reference Assemblies\Microsoft\WindowsPowerShell\v1.0

7. Right-click on your project and choose Add Reference...

8. Select the Browse Tab and locate these assemblies then add a reference to the System.Management.Automation.dll

9. Now that we have our reference we need to add some using/imports statements to make getting to the classes we want to use easier. Make sure to put these at the top of your code page outside any other code.

C#:

using System.Collections.ObjectModel; using System.Management.Automation; using System.Management.Automation.Runspaces; using System.IO;

10. Okay, this next part is a little funkier. While I liked the code that Mikkers had, I wanted to be able to load up a file from my file system and use it instead of just putting code into a textbox. That created some VERY interesting new challenges but the end result worked out well. So, to that end, we will create two helper methods: RunScript and LoadScript. RunScript is the code essentially unchanged from Mikkers' article and LoadScript is my helper function that will load the contents of a script file and return a string.

11. Let's begin with the RunScript method. We will add this method to the Form1 class to make our life easier.

// add an extra command to transform the script output objects into nicely formatted strings // remove this line to get the actual objects that the script returns. For example, the script // "Get-Process" returns a collection of System.Diagnostics.Process instances. pipeline.Commands.Add("Out-String");

' create a pipeline and feed it the script text Dim MyPipeline As Pipeline = MyRunSpace.CreatePipeline()

MyPipeline.Commands.AddScript(scriptText)

' add an extra command to transform the script output objects into nicely formatted strings ' remove this line to get the actual objects that the script returns. For example, the script ' "Get-Process" returns a collection of System.Diagnostics.Process instances. MyPipeline.Commands.Add("Out-String")

' convert the script result into a single string Dim MyStringBuilder As New StringBuilder()

For Each obj As PSObject In results MyStringBuilder.AppendLine(obj.ToString()) Next

' return the results of the script that has ' now been converted to text Return MyStringBuilder.ToString()

End Function

12. Now we want to add in our LoadScript method to make getting the script into a variable easier.

C#:

// helper method that takes your script path, loads up the script // into a variable, and passes the variable to the RunScript method // that will then execute the contents private string LoadScript(string filename) { try { // Create an instance of StreamReader to read from our file. // The using statement also closes the StreamReader. using (StreamReader sr = new StreamReader(filename)) {

// use a string builder to get all our lines from the file StringBuilder fileContents = new StringBuilder();

// string to hold the current line string curLine;

// loop through our file and read each line into our // stringbuilder as we go along while ((curLine = sr.ReadLine()) != null) { // read each line and MAKE SURE YOU ADD BACK THE // LINEFEED THAT IT THE ReadLine() METHOD STRIPS OFF fileContents.Append(curLine + "\n"); }

' helper method that takes your script path, loads up the script ' into a variable, and passes the variable to the RunScript method ' that will then execute the contents Private Function LoadScript(ByVal filename As String) As String

Try

' Create an instance of StreamReader to read from our file. ' The using statement also closes the StreamReader. Dim sr As New StreamReader(filename)

' use a string builder to get all our lines from the file Dim fileContents As New StringBuilder()

' string to hold the current line Dim curLine As String = ""

' loop through our file and read each line into our ' stringbuilder as we go along Do ' read each line and MAKE SURE YOU ADD BACK THE ' LINEFEED THAT IT THE ReadLine() METHOD STRIPS OFF curLine = sr.ReadLine() fileContents.Append(curLine + vbCrLf) Loop Until curLine Is Nothing

Updates the "Debug Managed Memory" feature to work on computers that have Windows Internet Explorer 9 installed.

MMA UI can be read by screen reader now.

Directed Graph Markup Language

Non-ENU Visual Studio crashes when the Legend in a DGML document is updated by disabling or deleting any item in the legend list.

Graphics Debugger

Graphics assets that are referenced by a graphics mesh are not deployed correctly.

When you capture a frame on a Windows 7 computer that does not have KB2670838 installed, you may receive the following error message:

The Graphics Diagnostics engine couldn't create a debug device, most likely because the matching Windows SDK for this version of Windows is not installed. Please install the matching SDK and try again.

Web Tools

Microsoft ASP.NET Web Frameworks and Tools (version 5.0.11213.0)

This release includes a new version of this product that adds editing support for ASP.NET MVC 5.1 on top of all existing functionality from the Web Framework and Tools 5.0 release

(http://www.asp.net/visual-studio/overview/2013/release-notes)

Nuget 2.7.2

This update will include Nuget 2.7.2. This release of Nuget will fix the scenario in which certain packages will fail when running package restore, update or uninstall. Release notes on additional features and bug fixes in Nuget 2.7.2 can be foundhere

(http://docs.nuget.org/docs/release-notes/nuget-2.7.2)

SignalR 2.0.1

This release includes updated SignalR item templates which now target the SignalR version 2.0.1: MS13-103

Projects may appear to have the SSL Enabled or SSL URL property set in Project Properties. However, these settings are not stored in the project file. Therefore, the SSL Enabled or SSL URL property is not actually enabled in the project.

Visual C++

Assume that you edit a dialog that contains at least one picture control in Resource Editor. After you save the file, the project can no longer be compiled.

Visual C++ IDE does not work as expected if there is an unexpected registry subkey under the following registry key:

HKCU\Software\Microsoft\VisualSTudio\12.0\FileExtensionMapping

When you try to link with PGO on amd64_x86 complier, Visual Studio crashes.

IntelliTrace

IntelliTrace Viewer is updated to support Internet Explorer 9.

Cloud Platform

"Object reference not set to an instance of an object" error message when an external user tries to save any intrinsic entity data from an Office 365-based cloud business application.

Visual Studio Test

Load Test

Visual Studio freezes when you try to run a load test in the cloud by using Visual Studio Online for the first time when there is no active connection to a Visual Studio Online account from your Team Explorer.

You cannot run load tests beyond 250 virtual users if you activated Visual Studio Ultimate by using an MSDN subscription.

When you activate Visual Studio by signing in to your Visual Studio online account by using your MSDN subscription id, you cannot run remote load tests, load tests together with a loadtest plugin or a virtual user load more than 250.

Load testing in Cloud with Visual Studio Online is broken on a computer that has Internet Explorer 9 installed. The Load Test Manager and Load Test Results windows do not render with Internet Explorer 9 correctly.

When there are multiple Visual Studio Online Accounts connected to in Visual Studio and none of them are active, one of the accounts is picked to communicate with the Load Testing in Cloud with Visual Studio Online, which results in a broken experience.

After you run a cloud-based load test by using Visual Studio Online, the "Download Result" operation fails for the first time. Additionally, you receive the following error message:

There was an error while importing the result file. Details: The system cannot find the file specified. After correcting the problem open the results from Load Test Manager.

XAML Tools

Improved the stability of the XAML designers in Visual Studio and Blend in a variety of scenarios for all XAML platforms (such as Windows Store, Windows Phone, Silverlight, WPF).

Addressed an issue concerning the packaging of Windows Store applications in which both XBF and XAML were packaged into a Windows Store AppX package when referencing Extension SDKs.

XAML Designer

Allow controls compiled for Windows 8 to display in the Toolbox for Windows 8.1 projects.

NOTE: This is an older feature I’ve updated the information for VS2013

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 or custom tokens? They seriously rock if you have never used them and, because they go in source code, everyone can have access to the information when you check-in the code!

TODO Comments

So here's how TODO comments work:

VB

In VB you just put any comment in that begins with the letters "todo" (case doesn't matter):

C# and C++

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

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

Note: You can Double Click any entry to automatically have the editor go to the respective line in your source.

If you don’t see the entries, make sure you have set the task list to see comments:

Custom Tokens

We actually have several tokens you can use in addition to TODO. To see all the existing tokens go to Tools | Options | Environment | Task List:

HACK and UNDONE

You are welcome to use HACK and UNDONE as well. The MSDN documentation is horrifically bad when it comes to describing these tokens and I don’t agree with the description of use necessarily. Here is what it says:

“Items labeled TODO, HACK, and UNDONE in the Task List window indicate code problems that do not keep the project from compiling, but that do cause run-time errors. You should correct these errors before running the project.”

Also, be aware that the number of entries that appear in the Task List changes depending on the type of project you are working on. With VB and C# projects, the Task List displays all of the comments in the project whether the file is open or not. With C++ projects, the Task List displays only the comments that are found in the files currently opened for edit.

Creating Custom Tokens

Feel free to create your own tokens for your use. Creating your own tokens is very simple, just pick a name for your token and type it in the Name textbox:

Note: UnresolvedMergeConflict looks like an error but isn’t it is an actual token that will make a high priority item in the Task List.

Finally

Tokens are a pretty nice feature to keep track of places in your code you need to revisit. I don’t suggest them over, say, tasks in Team Foundation Server but they are a great short-term reminder for things that need to get attention. If you decide you would like to create Task List items programmatically you can do that as well. Here is a link to some guidance to get you started:

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.

Mixed Case is Your Friend

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!

Manual Registry Change

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)

Create a new DWORD value called SuppressUppercaseConversion set to 1

Restart Visual Studio and you should see the change

NOTE: Watch your spelling if you are typing this manually.

PowerShell Goodness

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.

Go to the Start button and type powershell and select the Windows PowerShell Entry:

When working with code metrics, one of the least understood items seems to be cyclomatic complexity. Essentially, with cyclomatic complexity, higher numbers are “bad” and lower numbers are “good”. We use cyclomatic complexity to get a sense of how hard any given code may be to test, maintain, or troubleshoot as well as an indication of how likely the code will be to produce errors. At a high level, we determine the value of cyclomatic complexity by counting the number of decisions made in our source code. In this tip we will start out with a simple example of cyclomatic complexity to understand the concept quickly then give some additional information on actual usage and suggested limits. Finally, I’ve added a section of citations that can be used to dig deeper into this subject.

Cyclomatic Complexity: A Simple Example

Cyclomatic complexity is defined as measuring “the amount of decision logic in a source code function” [NIST235]. Simply put the more decisions that have to be made in code, the more complex it is.

Let’s see it in action. Create a new console application and immediately calculate your code metrics by going to Analyze | Calculate Code Metrics for Solution:

Notice the cyclomatic complexity is at 2 (the lowest value possible). If I add non-decision code, notice the complexity doesn’t change:

If I add a decision, the cyclomatic complexity value goes up by 1:

When I change the if statement to a switch statement with 4 decisions to be made then it goes from the original 2 to 6:

Notice that most of the items, as we drill down into the Products_Related class, have a value of 1 but a couple of them have a complexity of 5. By itself this may not be a big deal, but given that most other members have a 1 in the same class I would definitely look closer at those two items and see what is in them. You can do this by right-clicking the item and choosing Go To Source Code from the context menu. Let’s take a closer look at Product.set(Product):

Given all the if statements, we can see why the cyclomatic complexity is at a 5. At this point we may decide that this is an acceptable level of complexity or we might refactor to reduce the complexity.

The Magic Number

As with many metrics in our industry, there is no exact cyclomatic complexity limit that fits all organizations. However, [NIST235] does indicate that a limit of 10 is a good starting point:

“The precise number to use as a limit, however, remains somewhat controversial. The original limit of 10 as proposed by McCabe has significant supporting evidence, but limits as high as 15 have been used successfully as well. Limits over 10 should be reserved for projects that have several operational advantages over typical projects, for example experienced staff, formal design, a modern programming language, structured programming, code walkthroughs, and a comprehensive test plan. In other words, an organization can pick a complexity limit greater than 10, but only if it is sure it knows what it is doing and is willing to devote the additional testing effort required by more complex modules.” [NIST235]

Cyclomatic Complexity and Line Numbers

As I mentioned in vstipTool130 (“Code Metrics – Lines of Code”), just looking at the number of lines of code by itself is, at best, a very broad predictor of code quality. There is some basic truth to the idea that the more lines of code in a function, the more likely it is to have errors. However, when we combine cyclomatic complexity with lines of code then we have a much clearer picture of the potential for errors.

As described by the Software Assurance Technology Center (SATC) at NASA:

“The SATC has found the most effective evaluation is a combination of size and [Cyclomatic] complexity. The modules with both a high complexity and a large size tend to have the lowest reliability. Modules with low size and high complexity are also a reliability risk because they tend to be very terse code, which is difficult to change or modify.” [SATC]

The function contains one or more catch blocks. In previous versions of Visual Studio, catch blocks were not included in the calculation. In Visual Studio 2010, the complexity of each catch block is added to the complexity of the function.

The function contains a switch (Select Case in VB) statement. Compiler differences between Visual Studio 2010 and earlier versions can generate different MSIL code for some switch statements that contain fall-through cases.

Putting It All Together

The bottom line is that a high complexity number means greater probability of errors with increased time to maintain and troubleshoot. Take a closer look at any functions that have a high complexity and decide if they should be refactored to make them less complex.

Now that Visual Studio 2012 is pretty well baked I thought it would be good to start revisiting some of my favorite features again and introduce new ones. Since project round-tripping is one of my most favorite features I thought we would start with it.

The Dark Ages

In all prior incarnations of Visual Studio if you had an older version, VS2008 for example, and opened up the project in a newer version, VS2010 in this case, you had the option to convert the project. If you did the conversion it was a one-way trip. You couldn’t open the project again in VS2008 if you tried to go back. This has been the source of a lot of pain and suffering for developers who have to work with multiple versions of Visual Studio for a long, long time. We want the cool features of the latest IDE but still want others on our team to be able to open the solution in the older version of Visual Studio when they get the files from source control.

The Information Age

Visual Studio 2012 changes the game. You can now create projects in Visual Studio 2010 with Service Pack 1 then open those projects in Visual Studio 2012 and THEN open the project up again in VS2010 SP1. This works the other way, too! You can create projects in VS2012 (targeting Framework version 4 or less) then open the project in VS2010 SP1 and THEN open it up in VS2012 again. In other words, we now have project round-tripping capability so you can work with the latest features but still keep the solution compatible with team members using an older version of Visual Studio.

Putting it to the Test

Here are the steps you can take to test this for yourself:

Create a compatible project (see fine print below) in Visual Studio 2010 with Service Pack 1 and put in a little sample code.

Save and close the solution.

Open the solution (CTRL + SHIFT + O) in Visual Studio 2012 and add some more code. Notice there is no longer a prompt to convert the project that appears.

Save the close the solution.

Open the project up again in VS2010 SP1 and enjoy project round-tripping.

The Fine Print

As you probably guessed by now this doesn’t work with every project type and there are some limitations based on the project type you use. For the full list of project types and limitations you can go here:

If the Model-View-Controller (MVC) project uses version 3 or 4, you can open this project in Visual Studio 2012 RC. By default, Visual Studio 2010 with SP1 supports only MVC 2 and 3, and Visual Studio 2012 RC supports only MVC 3 and 4.

You can’t open this project in Visual Studio 2012 RC because it doesn't support that project type. We recommend that you use InstallShield Limited Edition for Visual Studio (ISLE), a free deployment solution that directly supports most Windows platforms and application runtimes. ISLE also supports importing data and settings from Visual Studio Installer projects. For more information, see Windows Installer Deployment.

Office 2010 VSTO

If the project targets the .NET Framework 4, you can open this project in both Visual Studio 2012 RC and Visual Studio 2010 with SP1.

SharePoint 2010

You can open the project in both Visual Studio 2012 RC and Visual Studio 2010 with SP1.

SQL Server 2008 R2 Express

If SQL Server 2008 R2 Express is installed on the computers that are running Visual Studio 2012 RC and Visual Studio 2010 with SP1, you can open the project in both of those versions of Visual Studio.

SQL Server Report Project

You can open the project in both Visual Studio 2012 RC and Visual Studio 2010 with SP1. For local mode only (that is, when not connected to SQL Server), you won’t get the design-time experience for controls that are associated with the viewer in Visual Studio 2010, but the project will function correctly at runtime.

Caution

If you add a feature that’s specific to Visual Studio 2012 RC, the report schema will be upgraded automatically, and you will no longer be able to open the project in Visual Studio 2010 with SP1.

If you allow Visual Studio to upgrade the project automatically, you can open it in both Visual Studio 2012 RC and Visual Studio 2010 with SP1.

Visual Studio 2010 Database (.dbproj)

If you convert the project to a SQL Server Data Tools Database project, you can open it in Visual Studio 2012 RC. However, Visual Studio 2012 RC doesn’t support the following artifacts:

unit tests

data-generation plans

data-comparison files

custom rule extensions for static code analysis

server.sqlsettings

.sqlcmd files

custom deployment extensions

partial projects (.files)

If you install SQL Server Data Tools, you can open the project in Visual Studio 2010 with SP1 after the migration. For more information, see Microsoft SQL Server Data Tools.

VS 2010 SQL Server Data Tools

You can open this project in both Visual Studio 2012 RC and Visual Studio 2010 with SP1.

Visual Studio Lab Management

You can use Microsoft Test Manager in Visual Studio 2010 with SP1 or Visual Studio 2012 RC to open environments that were created in either of these versions. However, your version of Microsoft Test Manager must match your version of Team Foundation Server before you can create environments. For more information, see Upgrading Lab Management Components from Visual Studio 2010.