Projects and Solutions

A C# program is built from source files, which are text files containing the code you write. Source code files are named with the .cs extension. The Program.cs file you created in Chapter 1 is an example.

A typical C# Express 2008 application can have a number of other files (such as assembly information files, references, icons, data connections, and more). C# Express 2008 organizes these files into a container called a project.

The C# Express Start Page is the first thing you’ll see when you start C# Express. From here, there are many different links to get you started.

Figure 2-1. The C# Express Start Page is the first thing you’ll see when you start C# Express. From here, there are many different links to get you started.

C# Express 2008 provides two types of containers for your source code, folders, files, and related material: the project and the solution. A project is a set of files that work together to create an executable program (.exe) or a dynamic link library (.dll). Large, complex projects may contain multiple .dll files.

A solution is a set of related projects, although it may also have just one project—which is what you’ll do most often in this book. Each time you create a new project, C# Express 2008 either adds it to an existing solution or creates a new solution.

Solutions are defined within a file named for the solution, and they have the extension .sln. The .sln file contains metadata, which is basically information about the data. The metadata describes the projects that compose the solution and information about building the solution. You won’t have to worry about these for the most part.

Tip

Visual Studio 2008 also creates a file with the same base name as the .sln file, but with the filename extension .sou (such as mySolution.sln and mySolution.sou). The .sou file contains metadata used to customize the IDE for the specific user.

There are a number of ways to open an existing solution. The simplest way is to select Open Project from the Start menu (which opens a project and its enclosing solution). Alternatively, you can open a solution in C# Express 2008 just by double-clicking the .sln file in Windows Explorer.

Typically, the build process results in the contents of a project being compiled into an executable (.exe) file or a dynamic link library (.dll) file. This book focuses on creating executable files.

Tip

The metadata describing the project is contained in a separate file named after the project with the extension .csproj. The project file contains version information, build settings, and references to other source files to include as part of the project.

Project Types

You can create many types of projects in the full version of Visual Studio 2008, including:

  • Console Application projects

  • Windows Application projects

  • Windows Service projects

  • WPF Application projects

  • WPF Browser Application projects

  • Windows Control Library projects

  • Web Control Library projects

  • Class Library projects

  • Smart device templates

  • Crystal Reports Windows Application projects

  • SQL Server projects

  • Word and Excel Document and Template projects

Note that web applications are missing from this list. Web applications do not use projects, just solutions.

Visual C# Express, being a “light” version of the Visual Studio product, can’t produce nearly as many types of projects. C# Express is limited to console applications, Windows Forms applications, WPF applications, WPF browser applications, and class libraries.

A typical .NET application comprises many items: source files (such as .cs files), assemblies (such as .exe and .dll files) and assembly information files, data sources (such as .mdb files), references, and icons, as well as miscellaneous other files and folders. Visual Studio 2008 makes all of this easier for you by organizing these items into a folder that represents the project. The project folder is housed in a solution. When you create a new project, Visual Studio 2008 automatically creates the solution.

Templates

When you create a new project with C# Express, you’ll see the New Project dialog box, shown in Figure 2-2.

The New Project dialog is where every new C# application starts.

Figure 2-2. The New Project dialog is where every new C# application starts.

In the New Project dialog, if you’re using Visual C# Express, you’ll see only the templates you can choose from for your project. If you’re using Visual Studio 2008, this dialog box will look different, with two panes. You select the project type (in the lefthand pane) and the template (in the right). There are a variety of templates for each project type. A template is a file that C# Express 2008 uses to set up the initial state of your project.

If you’re using Visual Studio 2008, for the examples in this book you’ll always choose Visual C# for the project type, and in most cases you’ll choose Console Application as the template. Specify the name of the directory in which your project will be stored in the Location box and name your project in the Name box. C# Express doesn’t give you the option of choosing the file location; the files are stored in your local My Documents folder, in a subfolder called Visual Studio 2008.

Tip

Project names can contain any standard characters, except leading or trailing spaces, Windows or DOS keywords, and any of the following special characters: # % & * | : " < > ? /.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset