One node is particularly noticeable, because the font is
boldfaced. This indicates that this project is the startup
project — in other words, the project that is launched when
you select Debug . Start Debugging or press F5. To change the
startup project, right-click the project you want to nominate and select Set as StartUp Project. It is
also possible to nominate multiple projects as startup projects via the Solution Properties dialog,
which you can reach by selecting Properties from the right-click menu of the Solution node.
fiGure 2-1
With certain environment settings (see “Let’s Get Started” in Chapter 1), the
Solution node is not visible when only a single project exists. The problem with
this is that it becomes difficult to access the Solution Properties window. To get
the Solution node to appear you can either add another project to the solution or
check the Always Show Solution item from the Projects and Solutions node in
the Options dialog, accessible via Tools . Options.
The toolbar across the top of the Solution Explorer enables you to
customize the way the contents of the window appear to you, as well
as giving you shortcuts to the different views for individual items. For
example, the first button, Show All Files, expands the solution listing
to display the additional files and folders, shown in Figure 2-2. You
can see that the My Project node is actually made up of multiple files,
which hold settings, resources, and information about the assembly.
In this expanded view you can see all the files and folders contained
under the project structure. Unfortunately, if the file system changes,
the Solution Explorer does not automatically update to reflect these
changes. The second button, Refresh, can be used to make sure you
are seeing the correct list of files and folders.
The Solution Explorer toolbar is contextually aware, with different buttons displayed depending
on what type of node is selected. This is shown in Figure 2-2, where a folder not contained in the
project (as indicated by the faded icon color) is selected and the remaining buttons from Figure
2-1 are not visible. In short, these buttons when visible can be used to view code (in this case, the
Window1.xaml.cs file) or open the designer, which displays both the design and xaml views of
the Window1.xaml file. Figure 2-2 also shows the Class Diagram button.
fiGure 2-2
The solution explorer .
17
If you don’t already have a class diagram in your project, clicking the View Class
Diagram button will insert one and automatically add all the classes. For a
project with a lot of classes, this can be quite time consuming and will result in a
large and unwieldy class diagram. It is generally a better idea to manually add
one or more class diagrams, which gives you total control.
common tasks
In addition to providing a convenient way to manage projects and items, the Solution Explorer has
a dynamic context menu that gives you quick access to some of the most common tasks, such as
building the solution or individual projects, accessing the build configuration manager, and opening
files. Figure 2-3 shows how the context menu varies depending on which item is selected in the
Solution Explorer.
fiGure 2-3
The first items in the left-hand and center menus relate to building either the entire solution or the
selected project. In most cases, selecting Build is the most efficient option, because it only builds
projects that have changed. However, in some cases you may need to force a Rebuild, which builds
all dependent projects regardless of their states. If you just want to remove all the additional files
that are created during the build process, you can invoke Clean. This option can be useful if you
want to package your solution in order to e-mail it to someone — you wouldn’t want to include all
the temporary or output files that are created by the build.
18 .
chaPter 2 The SoluTion explorer, Toolbox, And properTieS
For most items in the Solution Explorer, the first section of the context menu is similar to the right-
hand menu in Figure 2-3: the default Open and Open With items allow you to determine how the
item will be opened. This is of particular use when you are working with XML resource files. Visual
Studio 2010 opens this file type using the built-in resource editor, but this prevents you from making
certain changes and doesn’t support all data types you might want to include (Chapter 38 goes into
how you can use your own data types in resource files), Using the Open With menu item, you can
use the XML Editor instead.
The context menu for the Solution, Project, and Folder nodes contains the Open
Folder in Windows Explorer item. This enables you to open Windows Explorer
quickly to the location of the selected item, saving you the hassle of having to
navigate to where your solution is located and then fi nd the appropriate subfolder.
adding Projects and items
The most common activities carried out in the Solution Explorer are the addition, removal, and
renaming of projects and items. To add a new project to an existing solution, you select Add . New
Project from the context menu off the Solution node. This invokes the dialog in Figure 2-4, which
has undergone a few minor changes since previous versions of Visual Studio. Project templates can
now be sorted and searched. The pane on the right side displays information about the selected
project, such as the type of project and its description (Chapter 15 covers creating your own Project
and Item templates, including setting these properties).
fiGure 2-4
In the Installed Templates hierarchy on the left of the Add New Project dialog, the templates are
primarily arranged by language and then by technology. The templates include Office project types,
enabling you to build both application- and document-level add-ins for most of the Office products.
Though the Office add-ins still make use of Visual Studio Tools for Office (VSTO), this is built
The solution explorer .
19
into Visual Studio 2010 instead of being an additional installer. You’ll see in Chapter 19 how you
can use these project types to build add-ins for the core Office applications. There are also tabs
for Recent Templates and Online Templates. The Online Templates can be sorted and searched in
the same way as your Installed Templates, although the sort criteria has been extended to include
creation date, ratings, and downloaded frequency.
The other thing you will notice in this dialog is the ability to select different framework versions. If
you have existing projects that you don’t want to have to migrate forward to the new version of the
.NET Framework, you can still immediately take advantage of the new features, such as improved
IntelliSense. The alternative would have been to have both Visual Studio 2010 and a previous
version installed in order to build projects for earlier framework versions. The framework selection
is also included in the search criteria, limiting the list of available project templates to those that are
compatible with the selected .NET Framework version.
When you open your existing solutions or projects in Visual Studio 2010, they
will still go through the upgrade wizard (see Chapter 44 for more information)
but will essentially make only minor changes to the solution and project fi les.
Unfortunately, these minor changes, which involve the inclusion of additional
properties, will break your existing build process if you are using a previous
version of MSBuild. For this reason, you will still need to migrate your entire
development team across to using Visual Studio 2010.
One of the worst and most poorly understood features in Visual Studio is the concept of a Web Site
project. This is distinct from a Web Application project, which can be added via the aforementioned
Add New Project dialog. To add a Web Site project you need to select Add . Web Site from the
context menu off the Solution node. This displays a dialog similar to the one shown in Figure 2-5,
where you can select the type of web project to be created. In most cases, this simply determines the
type of default item that is to be created in the project.
fiGure 2-5
20 . chaPter 2 The SoluTion explorer, Toolbox, And properTieS
Once you have a project or two, you will need to start adding items. You do this via the Add context
menu item off the project node in the Solution Explorer. The fi rst submenu, New Item, launches the
Add New Item dialog, as seen in Figure 2 - 6.
fiGure 2 - 6
It is important to note that the types of web projects listed in Figure 2 - 5 are the
same as the types listed under the Web node in the Add New Project dialog.
However, understand that they will not generate the same results, because signifi cant
differences exist between Web Site projects (created via the Add New Web Site
dialog) and Web Application projects (created via the Add New Project dialog).
The differences between these project types are covered in detail in Chapter 20.
Like the New Project and New Web Site dialogs, the Add New Item dialog has also had a facelift.
In addition to listing only those item templates that are relevant to the project you have selected,
this dialog enables you to search the installed templates, as well as go online to look for templates
generated by third parties.
Returning to the Add context menu, you will notice a number of predefi ned shortcuts such as User
Control and Class. These do little more than bypass the stage of locating the appropriate template
within the Add New Item dialog. The Add New Item dialog is still displayed, because you need to
assign a name to the item being created.
It is important to make the distinction that you are adding items rather than fi les
to the project. Though a lot of the templates contain only a single fi le, some, like
the Window or User Control, will add multiple fi les to your project.
The solution explorer .
21
adding references
Each new software development technology that is released promises better reuse, but few are able
to actually deliver on this promise. One way that Visual Studio 2010 supports reusable components
is via the references for a project. If you expand out any project you will observe a number of .NET
Framework libraries, such as System and System.Core, that need to be referenced by a project in
order to be built. Essentially, a reference enables the compiler to resolve type, property, field, and
method names back to the assembly where they are defined. If you want to reuse a class from a
third-party library, or even your own .NET assembly, you need to add a reference to it via the Add
Reference context menu item on the project node of the Solution Explorer.
When you launch the Add Reference dialog, shown
in Figure 2-7, Visual Studio 2010 interrogates
the local computer, the Global Assembly Cache,
and your solution in order to present a list of
known libraries that can be referenced. This
includes both .NET and COM references that
are separated into different lists, as well as
projects and recently used references. In previous
versions of Visual Studio this dialog was
notoriously slow to load. If the component you
need to reference isn’t present in the appropriate
list, you can choose the Browse tab, which
enables you to locate the file containing the
component directly in the file system. By initially
loading the list of projects within your solution
and presenting that as the default tab, then lazy
loading the content for the remaining tabs, this
dialog now displays almost instantly.
As in other project-based development environments going back as far as the first versions of VB, you
can add references to projects contained in your solution, rather than adding the compiled binary
components. The advantage to this model is that it’s easier to debug into the referenced component
and helps ensure you are running the latest version of all components, but for large solutions this
may become unwieldy.
fiGure 2-7
When you have a solution with a large number of projects (large can be relevant
to your computer but typically anything over 20), you may want to consider
having multiple solutions that reference subsets of the projects. This will continue
to give you a nice debugging experience throughout the entire application while
improving Visual Studio performance during both loading and building of the
solution. Alternatively, you may want to create different build configurations
(see Chapter 45) to build a subset of the projects.
22 .
chaPter 2 The SoluTion explorer, Toolbox, And properTieS
adding service references
The other type of reference that the Solution Explorer caters to is service references. In previous
versions of Visual Studio this was referred to as web references, but with the advent of the Windows
Communication Foundation (WCF) there is now a more generic Add Service Reference menu item.
This invokes the Add Service Reference dialog, which you can see in Figure 2-8. In this example the
drop-down feature of the Discover button has
been used to look for Services in Solution.
Unfortunately, this dialog is another case
of Microsoft not understanding the usage
pattern properly. Though the dialog itself
is resizable, the status response message
area is not, making it hard to read any
errors generated. Luckily, if any errors are
thrown while Visual Studio 2010 attempts
to access the service information, it provides
a hyperlink that opens the Add Service
Reference Error dialog. This generally
gives you enough information to resolve
the problem.
In the lower left-hand corner of Figure 2-8 is an Advanced button. The Service Reference Settings
dialog that this launches enables you to customize which types are defined as part of the service
reference. By default, all local system types are assumed to match those being published by the
service. If this is not the case, you may want to adjust the values in the Data Type area of this dialog.