EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
92 .
chaPter 6
TemSiAnd ,projecTS ,onSi SoluT
In this example, the solution consists of a single project, FirstProject, and a Global section outlining
settings that apply to the solution. For instance, the solution itself will be visible in the Solution
Explorer because the HideSolutionNode setting is FALSE. If you were to change this value to TRUE,
the solution name would not be displayed in Visual Studio.
As long as a solution consists of projects that do not target the .NET Framework
version 4.0, you can open the solution with Visual Studio 2008 by performing a
quick edit to the .sln file. Simply replace the first two lines of the file with the
following, and the solution will open with no errors:
Microsoft Visual Studio Solution File, Format Version 10.00
# Visual Studio 2008
solution ProPerties
You can reach the solution Properties dialog by right-clicking the Solution node in the Solution
Explorer and selecting Properties. This dialog contains two nodes to partition Common and
Configuration properties, as shown in Figure 6-2.
fiGure 6-2
The following sections describe the Common and Configuration properties nodes in more detail.
common Properties
You have three options when defining the Startup Project for an application, and they’re somewhat
self-explanatory. Selecting Current Selection starts the project that has current focus in the Solution
Explorer. Single Startup ensures that the same project starts up each time. This is the default
selection, because most applications have only a single startup project. The last option, Multiple
solution Properties .
93
Startup Projects, allows for multiple projects to be started in a particular order. This can be useful
if you have a client/server application specified in a single solution and you want them both to be
running. When running multiple projects, it is also relevant to control the order in which they
start up. Use the up and down arrows next to the project list to control the order in which projects
are started.
The Project Dependencies section is used to indicate other projects on which a specific project
is dependent. For the most part, Visual Studio will manage this for you as you add and remove
project references for a given project. However, sometimes you may want to create dependencies
between projects to ensure that they are built in the correct order. Visual Studio uses its list of
dependencies to determine the order in which projects should be built. This window prevents you
from inadvertently adding circular references and from removing necessary project dependencies.
In the Debug Source Files section, you can provide a list of directories through which Visual Studio
can search for source files when debugging. This is the default list that is searched before the Find
Source dialog is displayed. You can also list source files that Visual Studio should not try to locate.
If you click Cancel when prompted to locate a source file, the file will be added to this list.
The Code Analysis Settings section is available only in the Visual Studio Team Suite editions. This
allows you to select the static code analysis rule set that will be run for each project. Code Analysis
is discussed in more detail later in the chapter.
configuration Properties
Both projects and solutions have build configurations associated with them that determine
which items are built and how. It can be somewhat confusing because there is actually no
correlation between a project configuration, which determines how things are built, and a
solution configuration, which determines which projects are built, other than they might have the
same name. A new solution will define both Debug and Release (solution) configurations, which
correspond to building all projects within the solution in Debug or Release (project) configurations.
For example, a new solution configuration called Test can be created, which consists of two projects:
MyClassLibrary and MyClassLibraryTest. When you build your application in Test configuration,
you want MyClassLibrary to be built in Release mode so you’re testing as close to what you would
release as possible. However, to be able to step through your test code, you want to build the test
project in Debug mode.
When you build in Release mode, you don’t want the Test solution to be built or deployed with
your application. In this case, you can specify in the Test solution configuration that you want
the MyClassLibrary project to be built in Release mode, and that the MyClassLibraryTest project
should not be built.
You can switch between configurations easily via the Configuration drop-down
on the standard toolbar. However, it is not as easy to switch between platforms,
because the Platform drop-down is not on any of the toolbars. To make this
available, select View . Toolbars . Customize. From the Build category on the
Commands, the Solution Platforms item can be dragged onto a toolbar.
94 .
chaPter 6 SoluTionS, projecTS, And iTemS
You will notice that when the Configuration Properties node is selected from the Solution
Properties dialog as shown in Figure 6-2, the Configuration and Platform drop-down boxes are
enabled. The Configuration drop-down contains each of the available solution configurations
(Debug and Release by default), Active, and All. Similarly, the Platform drop-down contains each
of the available platforms. Whenever these drop-downs appear and are enabled, you can specify
the settings on that page on a per-configuration and/or per-platform basis. You can also use the
Configuration Manager button to add additional solution configurations and/or platforms.
When adding additional solution configurations, there is an option (checked by default) to create
corresponding project configurations for existing projects (projects will be set to build with
this configuration by default for this new solution configuration), and an option to base the new
configuration on an existing configuration. If the Create Project Configurations option is checked
and the new configuration is based on an existing configuration, the new project configurations
will copy the project configurations specified for the existing configuration.
The options available for creating new platform configurations are limited by the types of CPU
available: Itanium, x86, and x64. Again, the new platform configuration can be based on existing
configurations, and the option to create project platform configurations is also available.
The other thing you can specify in the solution configuration file is the type of CPU for which you
are building. This is particularly relevant if you want to deploy to 64-bit architecture machines.
You can reach all these solution settings directly from the right-click context menu from the
Solution node in the Solution Explorer window. Whereas the Set Startup Projects menu item opens
the solution configuration window, the Configuration
Manager, Project Dependencies, and Project Build Order
items open the Configuration Manager and Project
Dependencies window. The Project Dependencies and
Project Build Order menu items will be visible only if you
have more than one project in your solution.
When the Project Build Order item is selected, this opens
the Project Dependencies window and lists the build order,
as shown in Figure 6-3. This tab reveals the order in which
projects will be built, according to the dependencies. This
can be useful if you are maintaining references to project
binary assemblies rather than project references, and it
can be used to double-check that projects are being built
in the correct order.
fiGure 6-3
ProJect tyPes
Within Visual Studio, the projects for Visual Basic and C# are broadly classified into different
categories. With the exception of Web Site projects, which are discussed separately later in this
chapter, each project contains a project file (.vbproj or .csproj) that conforms to the MSBuild
schema. Selecting a project template creates a new project, of a specific project type, and populates
Project Types .
95
it with initial classes and settings. Following are some of the more common categories of projects as
they are grouped under Visual Studio:
.
Windows: The Windows project category is the broadest category and includes most of the
common project types that run on end-user operating systems. This includes the Windows
Forms executable projects, Console application projects, and Windows Presentation
Foundation (WPF) applications. These project types create an executable (.exe) assembly
that is executed directly by an end user. The Windows category also includes several types
of library assemblies that can easily be referenced by other projects. These include both
class libraries and control libraries for Windows Forms and WPF applications. A class
library reuses the familiar DLL extension. The Windows Service project type can also be
found in this category.
.
Web: The Web category includes the project types that run under ASP.NET. This includes
ASP.NET web applications, XML web services, and control libraries for use in web
applications and rich AJAX-enabled web applications.
.
Office: As its name suggests, the Office category creates managed code add-ins for
Microsoft Office products, such as Outlook, Word, or Excel. These project types use Visual
Studio Tools for Office (VSTO), and are capable of creating add-ins for most products in
both the Office 2003 and Office 2007 product suite.
.
SharePoint: Another self-describing category, this contains projects that target Windows
SharePoint Services, such as SharePoint Workflows or Team Sites.
.
Database: The Database category contains a project type for creating code that can be
used with SQL Server. This includes stored procedures, user-defined types and functions,
triggers, and custom aggregate functions.
.
Reporting: This category includes a project type that is ideal for quickly generating complex
reports against a data source.
.
Silverlight: This contains project types for creating Silverlight Applications or Class Library
projects.
.
Test: The Test category includes a project type for projects that contain tests using the
MSTest unit testing framework.
.
WCF: This contains a number of project types for creating applications that provide
Windows Communication Foundation (WCF) services.
.
Workflow: This contains a number of project types for sequential and state machine
workflow libraries and applications.
The New Project dialog box in Visual Studio 2010, shown in Figure 6-4, allows you to browse
and create any of these project types. The target .NET Framework version is listed in a drop-down
selector in the top right-hand corner of this dialog box. If a project type is not supported by the
selected .NET Framework version, such as a WPF application under .NET Framework 2.0, that
project type will not be displayed.
96 .
chaPter 6
TemSiAnd ,projecTS ,onSi SoluT
fiGure 6-4
ProJect files forMat
The project files (.csproj, .vbproj, or .fsproj) are text files in an XML document format that
conforms to the MSBuild schema. The XML schema files for the latest version of MSBuild are
installed with the .NET Framework, by default in C:\WINDOWS\Microsoft.NET\Framework\
v4.0.20506\MSBuild\Microsoft.Build.Core.xsd.
To view the project file in XML format, right-click the project and select Unload.
Then right-click the project again and select Edit < project name >. This will
display the project file in the XML editor, complete with IntelliSense.
The project file stores the build and configuration settings that have been specified for the project and
details about all the files that are included in the project. In some cases, a user-specific project file is
also created (.csproj.user or .vbproj.user), which stores user preferences such as startup and
debugging options. The .user file is also an XML file that conforms to the MSBuild schema.
ProJect ProPerties
You can reach the project properties by either right-clicking the Project node in Solution Explorer
and then selecting Properties, or by double-clicking My Project (Properties in C#) just under the
Project node. In contrast to solution properties, the project properties do not display in a modal
Project Properties .
97
dialog. Instead they appear as an additional tab alongside your code files. This was done in part
to make it easier to navigate between code files and project properties, but it also makes it possible
to open project properties of multiple projects at the same time. Figure 6-5 illustrates the project
settings for a Visual Basic Windows Forms project. This section walks you through the vertical tabs
on the project editor for both Visual Basic and C# projects.
fiGure 6-5
The project properties editor contains a series of vertical tabs that group the properties. As changes
are made to properties in the tabs, a star is added to the corresponding vertical tab. This functionality
is limited, however, because it does not indicate which fi elds within the tab have been modifi ed.
application
The Application tab, visible in Figure 6-5 for a Visual Basic Windows Forms project, enables
the developer to set the information about the assembly that will be created when the project
is compiled. These include attributes such as the output type (that is, Windows or Console
Application, Class Library, Windows Service, or a Web Control Library), application icon, and
startup object. The Application tab for C# applications, shown in Figure 6-6, has a different format,
and provides options such as the ability to select the target .NET Framework version.
To change the .NET Framework version on a Visual Basic project, use the
Advanced Compile Options on the Compile tab.
98 .
chaPter 6 SoluTionS, projecTS, And iTemS
fiGure 6-6