Exercise 1: A Lap Around the Visual Studio 11 Development Environment

Task 1 – Project Compatibility

One of the pillars of this release is project compatibility from one version to the next. Now, you can open Visual Studio 2010 projects in Visual Studio 11 and continue working from Visual Studio 2010 without any problems since the project files are the same.

In this task, you will see how easy it is to migrate your solutions to Visual Studio 11 while maintaining compatibility with Visual Studio 2010. To learn about this feature, you will open a Visual Studio 2010 solution in Visual Studio 11, modify its contents and then reopen it in Visual Studio 2010.

  1. Start Visual Studio 2010.
  2. Select File | Open | Project/Solution. In the Open Project dialog, browse to Ex01-NewFeatures\Begin and select the CardGame.sln file.
  3. Press F5 to run the application.

    Figure 1

    The CardGame application.

  4. Close the application.
  5. Close Visual Studio 2010 and open Visual Studio 11.
  6. You will now open the Visual Studio 2010 solution from Visual Studio 11. Select File | Open | Project/Solution. In the Open Project dialog, browse to \Ex01-NewFeatures\Begin and select CardGame.sln file to open the solution. Upon starting this version you won’t be prompted to update your project.

    Note:
    As project files don’t require upgrading, you won’t see the Project Updater Wizard from the previous editions. If you have Visual Studio 2010 SP1, you can still open projects in Visual Studio 2010 after you’ve opened and saved them with Visual Studio 11.

  7. Double-click Program.cs file in the Solution Explorer to open it.
  8. Add a new comment at the beginning and press CTRL + S to save the file.

    C#

    // Testing project migration
    using System;
    FakePre-39828cd2b7654bea8d4cae041a4cd62a-876e80c965864ca2a030bc43b2f41b15FakePre-95b0a5444b63478b804b9253fdf6443b-e8a95785890d402bb494018dbb29a3baFakePre-4889ee2d458b45bba1505d736d248f68-77bbf9bd7ed0423a8697e8bfcb9cde65FakePre-563f6e6de50f4313ade70189f3fdadbf-8e018a4852d64f47b4a20f59c5e2af0aFakePre-a283479c7a1a44b183a55b294f1aa7ba-54707d674ce8476687a4a0d8a715daa6

    Note:
    Notice that the code editor now highlights the line where the cursor is positioned.

  9. Select File | Close Solution.
  10. Now you will make sure the project is still compatible with the previous version. Reopen Visual Studio 2010, select File | Recent Projects and Solutions, and select CardGame.sln from the list. The solution just opens.

Task 2 – Search Enhancements and Simplified Toolbars and Commands

  1. Return to Visual Studio 11.
  2. Reopen the CardGame solution. To do this, under the File menu, choose Open and then Project/Solution. In the Open Project dialog, browse to Ex1-NewFeatures in the Source folder of the lab. Select CardGame.sln in the Begin folder and then click Open.

    Another change/enhancement you might notice is the simplified toolbar. There are not as many buttons as in the previous version. By default, the new toolbar includes the commands most frequently used. Notice that commands have not been removed; the least used commands have been placed in the well of each command bar.

    Figure 2

    Simplified toolbar

    Note:
    You can import your Visual Studio 2010 settings into Visual Studio 11 just like in older versions. Check the following MSDN topic to learn how to share settings between Visual Studio versions: https://msdn.microsoft.com/en-us/library/1x6229t8.aspx

  3. The rest of the buttons on the toolbar are still present but are not enabled by default, so you can customize the toolbar by adding or removing any buttons you desire. To do this, click on the toolbar options button at the right end of the toolbar, select Add or Remove Buttons and check the buttons you wish to display on the toolbar.

    Figure 3

    Add or remove buttons

    Note:
    You can reset a toolbar to its original configuration by opening the Tools | Customize dialog and using the Commands tab.

  4. Open several code files from the solution. Switch from one code file to another. Use the Navigate Backward and Navigate Forward buttons to navigate through the files. Notice the navigation buttons are on the left side of the toolbar for better access. Additionally, the Navigate Back/Forward feature has been enhanced not only to go back to open files, but also to navigate to files that were closed or opened provisionally.

    Figure 4

    Navigation buttons

  5. The second thing you might notice is the search box in the top right corner. This quick launch box can be used to search for and execute any command you need. You do not need to look through all the menus or memorize shortcuts. Start typing a command name in the quick launch box, for instance “new project”. Notice that results start to appear immediately, and you can see the matching shortcuts and their locations.

    Figure 5

    Quick Launch

  6. Now type a new command, for instance “build solution”, and press ENTER to build the solution. Notice how easy and fast it is to find and execute IDE commands.
  7. Quick launch searches for more than just commands. For example, if you want to change the font used by the editor, type “font” and press ENTER to open the Fonts and Colors options.

    Figure 6

    Quick launching the fonts and colors option

  8. Open the BlackJackGame\Player.cs file. Comment out the line of code that defines the balance member.

    Figure 7

    Comment out this line of code

  9. Select View | Error List to open the Error List window.

    Figure 8

    The Error List

  10. The search function has been integrated in other tool windows to make it easier and faster to find things, avoiding the need to scroll through long lists of items. Type extension in the Search Error List text box. Only the errors that contain that text appear.

    Figure 9

    Search in Error List

  11. Click the X in the search text box to clear the text. You should see all of the errors.
  12. Uncomment the line of code you previously commented.

    Figure 10

    Uncomment this line of code

  13. Open the CardGameFramework\Hand.cs file. Comment out the line of code that defines the FaceVal member.
  14. Build the solution. In the Error List window, notice there are errors in two different code files.

    Figure 11

    There are errors in two code files

  15. Select Current Document from the filter drop-down list in the upper left of the Error List window. This filters the errors and shows there are no errors in the Card.cs file.

    Figure 12

    Filtering the Error List

  16. Select the Hand.cs code file. The Error List displays only the errors in that file.

    Figure 13

    Only the errors in Hand.cs appear in the Error List

  17. Select Current Project from the filter drop-down list in the upper left of the Error List window to display all errors.
  18. Return to the Card.cs file and uncomment the line of code that defines the FaceVal member. Build the solution. There should be no errors.
  19. In Solution Explorer, double-click the StartForm.cs file to open it in design mode.
  20. Notice that there is also a search box in the Toolbox to be able to find the controls you need faster and without scrolling. For example, type “button” to quickly find the Button control.

    Figure 14

    Search in the Toolbox

Task 3 – Solution Explorer New Features

The Solution Explorer is significantly enhanced in the new version of Visual Studio. It now combines the code browsing features of Class View, Object Browser, Find References, Navigate To, and more into a single tool window. The Solution Explorer not only enables you to browse the solution files, but also the content within the code files, including types, members, callers, etc. You can navigate easily across the entire code structure. In the following steps, you will explore these features and more.

Note:
To take full advantage of the new Visual Studio 11 development environment features, it is recommended you have Windows Aero Theme enabled.

  1. In the Solution Explorer, click the Collapse All button. This simple feature will help you to access and organize your code when you have multiple projects in one solution. Now click the arrow icon next to the CardGame project to expand it.

    Figure 15

    Collapsing the entire solution

  2. Expand the BlackJackGame or CardGameFramework folder and click on one of the code files. That code file appears in the preview tab. To open a file in the preview tab you can either click the Open button in the preview tab or start typing. To close the preview tab you can click the Close button.

    Figure 16

    The code file appears in the preview tab

    If you want to select a file without previewing it, hold down the Alt key. Click the Preview Selected Items button in the Solution Explorer to toggle single click previewing on and off. You can also turn it on and off in the Options dialog box.

    Figure 17

    Toggle single click previewing on and off

    Figure 18

    Control the preview tab using the Options dialog

  3. Click the Program.cs file once to select it, and then click it again to rename it (you can also right-click over the file and select the Rename option from the menu). Notice that only the class name is selected. You will find a number of these small enhancements that should improve the usability of Solution Explorer.

    Figure 19

    Renaming a project item

  4. Another new feature is the ability to preview project images without opening them. To do that, expand the Images | Cards folder and move the mouse pointer over the elements.

    Note:
    Windows Aero Theme has to be enabled to make image thumbnails work.

    Figure 20

    Preview an image

  5. The Solution Explorer now includes an integrated search. Click on Search Solution Explorer or press CTRL + ; and type player to find all its occurrences in the solution. Note that includes file names as wells as class, member and event names.

    Figure 21

    Solution search results

    Note:
    Search results are shown hierarchically, which makes it easier to see where the results are coming from. You can also collapse the elements you don’t want in order to only show the relevant results.

  6. Since the search box uses the same algorithms as the Navigate To tool window, it supports fuzzy search capabilities and CAML Casing. For example, type BJG to view the contents of the BlackJackGame.cs file.

    Figure 22

    Searching with CAML casing

  7. Click the back button in the Solution Explorer toolbar to return to the previous view. This version of the Solution Explorer can also navigate backward and forward.

    Figure 23

    Back button

  8. Expand Player.cs and the Player class to display its properties and methods. Visual Studio 11 integrates the Class Member feature with the Solution Explorer, showing information about project files and class structures in the same window.

    Figure 24

    Viewing class members

    Note:
    Not only can you browse the files within a project, but you can also drill down to explore the contents of those files as well.

  9. Select any class member and double-click it to open its declaration. You won’t need to scroll through the class to locate a specific piece of code because you can now find it directly by clicking any of the members.

    Note:
    The goal of these new features is to keep the number of open tool windows to a minimum and to avoid spending as much time organizing your environment.

  10. The Solution Explorer helps you better understand the structure of your code. Right-click the Hand class node to show the lists of dependencies for that node in the tree. Check out each of the following options. To return from each view you can click the Back button.

    Class menu

    Figure 25

    View a list of dependencies for a class

    1. Scope to This

      This option shows class components. This is an overall view for class members and helps you identify the main components. For instance, these are the Hand class components:

      Figure 26

      Hand class components

    2. Base Types

      This option displays all the base types of the class.

      Figure 27

      Hand class base types

    3. Derived Types

      This option shows the derived types of a class, which is useful in identifying inheritance relationships. In the following example, you will see that BlackJackHand is the only derived type of the Hand class.

      Figure 28

      Derived types of the Hand class

    4. Is Used by

      This option shows a list with all the elements that use the selected class (same as Find all References). By double-clicking each item, you can directly open its code.

      Figure 29

      Users of the Hand class

      Note:
      You will find this option valuable when you work on code modifications or refactoring, as it helps you to know exactly where a class is declared.

  11. You will now repeat the previous step on a property. Right-click on the NumCards property in the Hand class in the Hand.cs code file to display the dependencies for the property. Select each of the options available.

    Figure 30

    Property dependencies

    1. Calls

      Figure 31

      Calls of a property

    2. Is called by

      Figure 32

      Callers of a property

    3. Is Used by

      Figure 33

      Users of a property

  12. Next, right-click the GetSumOfHand method of the BlackJackHand class in the Hand.cs code file and select Is Called by. You will see the complete chain of method calls, from the user interface to the class.

    Figure 34

    Callers of the GetSumOfHand method

  13. You can open the Solution Explorer in a separate window, which enables you to maintain multiple views of your projects and code. Click on the New Window icon located on the right side of the toolbar. This enables you to keep multiple Solution Explorer windows open in different views without scrolling and collapsing elements. You can move the various Solution Explorer windows to a different monitor if you are using more than one.

    Figure 35

    Two Solution Explorers open with the same content

  14. Clicking the New Window button creates a duplicate of the Solution Explorer. You can also create a copy that is scoped to a file, class or member. Right-click the Card class in the Card.cs file and select New View. The new Solution Explorer window contains only that class.

    Figure 36

    Two Solution Explorers open with different content

  15. Open a number of code files. Select the tab of each code file and notice that the Solution Explorer keeps track of the active file. This causes the selection rectangle to jump around in the Solution Explorer. To turn this behavior off type track active item in the Quick Launch text box and select Projects and Solutions – General to display the Options dialog box. Uncheck Track Active Item in Solution Explorer and click OK.

    Figure 37

    Turn tracking of the active item on or off

  16. Now as you select the tab of each code file, the Solution Explorer does not update to show you the active file. To show the active file, click the Sync with Active Document button in the Solution Explorer.

    Figure 38

    Sync the Solution Explorer with the open document

Task 4 – Enhanced Document Management

When coding in Visual Studio you often have a great number of documents open simultaneously that do not fit in the tab well and can become difficult to manage. Visual Studio 11 includes some document management enhancements to make it easier to develop with the multiple code files and documents in your solutions.

  1. Visual Studio now provides the ability to pin tabs. This enables you to easily keep the files you use most on the left-hand side of the tab well. Any other documents you open will not affect your pinned tabs. Try opening several code files and clicking the pin icon in the document tab to pin several of them. Then open more documents and see how newly opened documents are placed to the right of the pinned tabs.

    Figure 39

    Pinning tabs

  2. Additionally, Visual Studio 11 provides an option to keep all pinned tabs on a separate row of the tab well. To enable this option, type Tabs in the Quick Launch window and then select Environment | Tabs and Windows. Select Show pinned tabs in a separate row. You can see how pinned tabs are placed above the others.

    Figure 40

    Control tab pinning in the Options dialog

    Figure 41

    Pinned tabs in a separate row

    Note:
    Visual Studio 11 also makes it easier to leverage multiple monitors. In Visual Studio 2010, it was possible to undock windows from the IDE and move everywhere on the desktop, however you could not dock different document or tool windows together. In Visual Studio 11 you have the ability to float windows outside the IDE (to different monitors if you want) and dock them together.

  3. Press the Windows key + LEFT ARROW to dock the main Visual Studio window to the left side of the screen.
  4. Drag one of the document tabs to the right side of the screen, press the Windows key + RIGHT ARROW to dock the window to the right. Notice that it has a frame around it; it is not just a document tab. It is a tab inside another document as well. For simplicity let’s assume each side represents a different monitor.
  5. Drag more document tabs to the right document well. Then click the new window button in Solution Explorer and drag the new instance to the right side as well. Notice that the guide diamond helps you dock the window to any part of the new well.

    Figure 42

    Simulating the multiple monitor support

    Note:
    In a multiple project scenario, you could use different monitors to create smaller scoped subsets of the files and projects you are working with, all spread across multiple monitors.

  6. Notice that you can preview both windows in the Windows Taskbar. Finally, you can press CTRL and double-click on the well title to move the windows back into Visual Studio.

    Figure 43

    Previewing the windows

    Note:
    Notice that you can pin or unpin code windows in both document wells.

  7. Earlier you saw that you can preview documents by selecting them in the Solution Explorer. You can also preview documents when debugging your code.
  8. Open the Program.cs code file. Place a breakpoint in the Main method and close the document. Press F5 to debug the application.

    Figure 44

    Adding a breakpoint

  9. Once the debugger stops in the breakpoint, press F11 to step into a method call. The StartForm.Designer.cs file opens in the preview tab.

    Figure 45

    Using the preview tab while debugging

  10. Press SHIFT+F5 to stop debugging.

Task 5 – Find and Replace

To provide a better search experience for developers as well as a cleaner design, Visual Studio 11 introduces a new Find and Replace feature. It requires very little screen space, provides instant results while you type, and what is more, highlights all the results on the code so you can read them while you work. Additionally, it now accepts .NET regular expressions to execute advanced searches.

  1. Press CTRL + F. The new Find box user interface appears in the upper-right corner of the active window.
  2. You can see instant results while you search. Type any expression in the find textbox and notice how results appear highlighted in the code file at the same time you type.

    Figure 46

    New Find box

  3. Press CTRL + H. The new Find and Replace box user interface appears in the upper-right corner of the active window.

    Figure 47

    New Find and Replace box

  4. You can change the search scope, which in prior editions was limited to the document at hand.

    Figure 48

    Search within a document

  5. You can scroll through the results from the search dialog. Click the right arrow button to move forward or open the menu and use the left arrow button to move backward.

    Figure 49

    Navigating the results backward and forward

  6. The search dialog box integrates advanced options with search history. Expand the search options using the arrow at the right of the box to display the Search options and the search history list.

    Figure 50

    Search options

  7. Visual Studio 11 now supports .NET Regular Expressions in the Find dialog box. Check the Use Regular Expression option in the Search options list and type a regular expression using .NET syntax for regular expressions. For instance, you can type private.*b to find all the private members that start with b.

    Figure 51

    Using .NET Regular expressions

Task 6 – Add Reference Dialog

Note:
This task applies to Visual Basic, Visual C# and Visual F#.

Visual Studio 11 includes an improved and easier to use Reference Manager dialog box. In prior versions, references were grouped in tabs and were filtered by the Framework version of the project target framework. Besides user interface issues, it was difficult to add references that corresponded to a different .NET Framework version.

Visual Studio 11 lists all the references in the same place, so you can scroll through, search and select the ones you will use or have previously added. Additionally, references are now added asynchronously so the development environment remains responsive.

  1. Select Project | Add Reference to display the Reference Manager dialog box. Notice that included references are checked.

    Figure 52

    References Manager dialog

  2. In the top right corner you will find the Search box, which will help you locate assemblies. For example, type office and all the references that match the term will appear in the list.

    Figure 53

    Searching for assemblies

  3. In the left pane you can filter the references by Assemblies, Solution or COM. This pane replaces the tabs from previous editions. You can also click the Browse button to add any library from your file system.

    Figure 54

    COM libraries

  4. Select Assemblies in the left pane. Notice that some of the listed assemblies are greyed out. The CardGame project was built with Visual Studio 2010 and targets the .NET Framework 4.0 Client Profile. The greyed out assemblies are not in the Client Profile.

    Figure 55

    Assemblies in a different target framework are greyed out

  5. Visual Studio 11 makes it is easier to include a reference from a version of the .NET Framework different from the one a project targets. Check System.Web and click OK. Notice that Visual Studio alerts you that the project will be retargeted to the full .NET Framework 4.

    Figure 56

    Adding a reference from a different .NET Framework target

Task 7 – Create Projects From Online Samples

When you are learning to build applications, you have likely found a large number of online samples you can download and use. Visual Studio 11 makes this easier by providing the ability to create new projects based on online samples.

  1. Select File | New Project. Select Online in the left pane. Visual Studio displays online templates and samples.
  2. Expand the Visual C# node within the Samples node and select Desktop.

    Figure 57

    Create a project from an online sample

  3. Name the project and solution and click OK.

Task 8 – Using the Help Viewer

Note:
This task applies to Visual Basic, Visual C# and Visual F#.

The Help Viewer is the user interface you use to view offline help. There are a number of enhancements to the Help Viewer in Visual Studio 11.

When you start Visual Studio for the first time, you are prompted to select your default environment settings. You will now be prompted to install offline documentation. The default is to install the minimum set of documentation. You can also choose the amount of documentation to install. If you choose Minimum, Visual Studio installs the core help for the Environment and the .NET Framework.

Figure 58

Select the amount of local help to install

In the following, you will explore some of the new features in the Help Viewer.

  1. In Visual Studio, select Help | Set Help Preference | Use Local Help.

    Figure 59

    Select to use Local Help

  2. To view local help, either select Help | View Help or press CTRL + F1. Expand the .NET Framework 4.5 Beta and Visual Studio 11 Beta nodes on the CONTENTS pane.

    Figure 60

    Local help

  3. You can add additional local help from the Manage Content tab of the Help Viewer. If the Help Viewer is not open, you can select Help | Add and Remove Local Help Content from within Visual Studio.
  4. Select a help topic. The Help Viewer displays a description of the topic. It also alerts you if there has been an update to documentation you have already downloaded.

    Figure 61

    Add or remove Local Help content

  5. Click Add to select the documentation for downloading. The Help Viewer displays the amount of disk space the content will require. Click Update to download the documentation.

    Figure 62

    Add a document set to local help

  6. The Help Viewer enables filtering of content. Click in the Filter Contents text box. Enter httpclient and press Enter. The Help Viewer displays the HttpClient topic.

    Figure 63

    Filtered help

  7. On the INDEX tab, enter httpclient in the filter text box.

    Figure 64

    Show index topics that contain HttpClient

  8. Click the Contains button to the left of the text box and the Help Viewer displays only topics where they keyword contains HttpClient.

    Figure 65

    Show index topics where the keyword contains HttpClient

  9. Select HttpClient class in the index list to display the help topic.
  10. Right-click on the help topic and select Add to Favorites.
  11. Select the FAVORITES tab to see that you have added the topic to your favorites.

    Figure 66

    Add help topics to your favorites

  12. Click History to see a history of the help topics you have viewed.

    Figure 67

    View a history of help topics you have viewed

  13. Select the SEARCH tab. Type GetAsync and press Enter. The Help Viewer displays topics that contain that text.

    Figure 68

    Search for GetAsync in the documentation