Book Image

Visual Studio 2013 and .NET 4.5 Expert Cookbook

Book Image

Visual Studio 2013 and .NET 4.5 Expert Cookbook

Overview of this book

Table of Contents (14 chapters)
Visual Studio 2013 and .NET 4.5 Expert Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Exploring the Command and Immediate windows


The Command window in the Visual Studio IDE is a special window that is useful to invoke commands inside Visual Studio; either those that are available through menu commands or that are hidden inside the IDE. You can use the Command window to edit, test, build, and debug applications. Instead of using the mouse to search commands, seasoned users of Visual Studio can save a considerable amount of time by using the Command window.

How to do it...

Being the most important part of the debugging tool, let's inspect how to use the Command and Immediate windows in the following steps:

  1. To display the Command window, select Other Windows in the View menu and select Command Window, or simply press Ctrl + Alt + A on the keyboard.

  2. When you are in the Command window, you will see a > symbol placed before every input. This is called a prompt.

  3. The Command and Immediate windows are very powerful. Almost every commonly used command that you can invoke from the IDE is available as a command from these windows. Let's start operating the Command window by using Build.Compile.

    The very first thing that you will notice is the lntelliSense menu that pops up as you start typing. When you press enter to run the command, the project will be compiled. This is the same as pressing F6. Similarly, you can use Debug.Start to start debugging the application.

    The Command and Immediate windows can help with things that are hard to find and not just the items that you can easily find inside the IDE. Type Debug.ListMemory when you are in a breakpoint. You will see the list of memory used with the current line. You can explore the Build and Debug menus to find out more interesting commands such as these.

  4. Let's look at some of the shortcuts available for the Command or Immediate windows:

    • ?: This gives you the value of a variable (you can also use Debug.Print to do the same)

    • ??: This sends the variable to the Watch window

    • Locals: This shows the Locals window

    • Autos: This shows the Autos window

    • GotoLn: This sets the cursor to a specific line

    • bp: This places a breakpoint to the current line

Similar to the Command window, the Immediate window lets you test the code without having to run it. The Intermediate window is used to evaluate, execute statements, or print variable values.

To open the Immediate window, navigate to Debug | Windows and select Immediate.

Tip

You can move back to the Immediate window by typing immed and to the Command window by typing the cmd command.

How it works…

Visual Studio is a huge environment with a lot of API support exposed from within it. Each of these sets of API commands are exposed through the Command window such that you can easily execute them by writing the command directly being within the IDE. Some of the commands that you can invoke through the Command window are still available to the IDE itself as visual tools, but there are a number of other commands that are not often used and are hidden from the normal users. They can be invoked only using commands. The Command window lets the user invoke commands on Visual Studio either in the debugging mode or in the normal mode. It would be good to specify some of the commands that are not available in the normal mode, for instance, Debug.BuildSolution or anything associated with the Debug interface. Some of the commands such as Build.AttachtoProcess or anything associated with the build interface are available only in the normal mode.

Immediate windows are generally used while debugging. It is the most popular tool to evaluate expressions at runtime, create variables on the fly, and/or print values.

Some of the commonly used commands in the Visual Studio IDE are associated with a command alias. For instance, if you use ?, it is equivalent to Debug.Print, the ?? command is equivalent to Debug.QuickWatch, addproj is equivalent to File.AddNewProject, tabify is used to invoke Edit.TabifySelection, and so on. You can use interfaces in the Command window, such as Debug, File, Edit, View, Tools, and Window, each of which provides a lot of the associated commands.

There's more…

Now let's consider some of the other items that you need to know.

The differences between the Command and Immediate windows

Even though both the Command and Immediate windows can be used interchangeably while debugging an application, there is one basic difference between the use cases of these windows.

The Command window is used to execute commands or aliases directly from being within the IDE. You can execute almost all the commands that are either available in menus of the IDE or hidden somewhere. The Command window can load dlls or packages into the IDE as well.

The Immediate window, on the other hand, is solely used during debugging and is useful to execute statements, print values of a contextual variable, or even evaluate expressions. Generally, the Immediate window is quite capable of executing large expressions while being in the debugging mode in the same way as it does inside Watch windows.

See also…