Managing Projects

When you create an application in Visual C# 2008, you work in the context of a "project." A project contains all the files and configuration data required to create your end product, an executable .exe or .dll file. In the world of the .NET Framework, this is referred to as an assembly. During the build process, Visual C# Express Edition also puts all your project resources, icons, audio files, and so on, into the executable file. In addition, it includes information called references that describe the other .dll or .exe files that your application will require when it runs.

You don't have to understand all the details about projects before you begin writing code. In fact, for simple applications, you can usually just accept the default project settings. But at some point, you might want to change the name of your executable file, customize some aspect of the build process, add a reference to a .dll, or strengthen the security settings. To make these changes, you will be using Solution Explorer, a window which displays all your project items in one convenient area, and the Project Designer, which enables you to modify many different aspects of your project.

The following illustration shows Solution Explorer for a Windows Forms project that has been created by clicking New Project on the File menu, selecting the Windows Forms Application icon, and using the default names provided by Visual C# Express Edition.

Solution Explorer displays your project files

The following discussion focuses on the project properties, which are settings that enable you to customize your project in various ways.

Project Properties

Project properties are grouped into 10 pages in the Project Designer. You can access the Project Designer in the Project menu by clicking Properties, or by right-clicking the Properties item in Solution Explorer. The Project Designer property pages are located in the same middle pane used by the Forms Designer and code editor.

The following illustration shows the user interface for the Project Designer:

Application property page

In the earlier illustration, the Application property page is displayed. By clicking the labels on the left tab, Build, Build Events, Debug, and so on, you can access the corresponding property page. The information entered here is stored in a .csproj file. You won't see the file in Solution Explorer, but it is located in the project folder on the drive. While you are working in Visual C# Express, you can access Help for any one of the property pages by positioning the pointer on the page and pressing F1.

The following table provides a brief description of each page in the Project Designer:

Property Page

Description

Application

Change the name of the assembly, the project type, assembly information including version number, and other resource options. For more information, see Application Page, Project Designer (Visual Basic).

Build

Change the location in which the compiled assembly is stored, conditional compilation options, how errors and warnings are handled, and other settings. For more information, see Build Page, Project Designer (C#).

Build Events

Create and modify custom build steps. For more information, see Build Events Page, Project Designer (C#).

Debug

Specify the command-line arguments when you are running under the debugger, and other settings. For more information, see Debug Page, Project Designer.

Resources

Add strings, icons, images or other types of files to your project as resources. For more information, see Resources Page, Project Designer.

Settings

Store settings such as connection strings for a database or the color-scheme that a particular user wants to use. These settings can be retrieved dynamically at run time. For more information, see Settings Page, Project Designer.

Reference Paths

Specify the path where assemblies referenced in your project are located. For more information, see Reference Paths Page, Project Designer (C#).

Signing

Specify ClickOnce certificate options, and provide strong name for your assembly. For more information, see Signing Page, Project Designer and ClickOnce Deployment Overview.

Security

Specify security settings that your application requires in order to run. For more information, see Security Page, Project Designer.

Publish

Specify options for distributing your application to a Web site, ftp server, or file location. For more information, see Publish Page, Project Designer.

References

In the context of a project, a reference identifies a binary file that your application requires in order to run. Typically, a reference identifies a .dll file such as one of the .NET Framework class library files, or a COM object if you are calling native Win32 functions. If your program creates an instance of a class that is defined in some other assembly, you must add a reference to that file in your project before you compile your project. To add a reference, click Add Reference on the Project menu. By default, all C# projects include a reference to mscorlib.dll, which contains the core .NET Framework classes. You can add references to additional .NET Framework .dll files and other files by clicking the Project menu and selecting Add Reference.

Note

Do not confuse the concept of a project reference with the concept of reference types in C# or other programming languages. The former refers to a file and its expected location on disk. The latter refers to C# types which are declared by using the class (C# Reference) keyword.

Resources

A resource is data that is included with your application but is stored in such a way that it can be modified independently from the other source code. For example, you can store all your strings as resources instead of hard-coding them into the source code. The five types of resources defined by Visual C# Express Edition are as follows: strings, images, icons, audio, and files. You add, remove, or edit resources by using the Resource Designer, which is accessed on the Resources tab in the Project Designer.

Forms

When you create a Windows Forms project, Visual C# Express Edition adds one form to the project by default and names it Form1.designer.cs. You can add a new form by clicking the Project menu and selecting Add Windows Form. Each form has two files associated with it. Form1.cs, or whatever you might name it, contains the source code that you write to configure the form and its controls, such as list boxes and text boxes, and to respond to events such as button clicks and key presses. In simple Windows Forms projects, you will do most or all coding in this file.

The "Designer.cs" file contains the source code that the Forms Designer writes when you drag controls onto the form, set properties in the Properties window, and so on. Typically, you do not edit this file manually at all.

Note

Obviously, projects for console applications do not contain source code files for Windows Forms.

Other Source Code Files

A project may include any number of additional .cs files that may be associated with a particular Windows Form. In the previous illustration of Solution Explorer, program.cs contains the entry point for the application. A single .cs file can contain any number of class and struct definitions. You can add new or existing files or classes to your project by clicking Add New Item or Add Existing Item on the Project menu.

See Also

Concepts

Introducing the Visual C# Express Development Environment

Other Resources

Using the Visual C# Express IDE