Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Visual Studio 2013 and .NET 4.5 Expert Cookbook

You're reading from   Visual Studio 2013 and .NET 4.5 Expert Cookbook Over 30 recipes to successfully mix the powerful capabilities of Visual Studio 2013 with .NET 4.5

Arrow left icon
Product type Paperback
Published in Sep 2014
Publisher
ISBN-13 9781849689724
Length 308 pages
Edition 1st Edition
Arrow right icon
Author (1):
Arrow left icon
Abhishek Sur Abhishek Sur
Author Profile Icon Abhishek Sur
Abhishek Sur
Arrow right icon
View More author details
Toc

Table of Contents (9) Chapters Close

Preface 1. A Guide to Debugging with Visual Studio FREE CHAPTER 2. Enhancements to WCF 4.5 3. Building a Touch-sensitive Device Application Using Windows Phone 8 4. Working with Team Foundation Server 5. Testing Applications Using Visual Studio 2013 6. Extending the Visual Studio IDE 7. Understanding Cloud Computing with Windows Azure 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…

You have been reading a chapter from
Visual Studio 2013 and .NET 4.5 Expert Cookbook
Published in: Sep 2014
Publisher:
ISBN-13: 9781849689724
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €18.99/month. Cancel anytime