In Chapter 2 you learned that you can create your C# applications using Notepad. In this chapter, you’ll learn why you never will. Microsoft developed Visual Studio .NET (VS.NET) to facilitate the creation of Windows and web applications. You will find that this Integrated Development Environment (IDE) is a very powerful tool that will greatly simplify your work.
Visual Studio .NET offers many advantages to the .NET developer. The following features are discussed in this chapter:
A modern interface using a tabbed document metaphor for source code and layout screens, and toolbars and informational windows that dock where you want them
Code completion, which allows you to enter code with fewer errors and much less typing
IntelliSense, which pops up help on every method and function call as you type
Dynamic, context-sensitive help, which allows you to view topics and samples relevant to the code you are writing at the moment
Immediate flagging of syntax errors (e.g., missing characters, misplaced braces, etc.), which allows you to fix problems as they are entered
The ability to compile and test programs right in the IDE
A built-in task list to keep track of changes you need to make
A Start Page that provides easy access to new and existing projects
Customization capability, which allows you to set user preferences for IDE appearance and behavior
One VS.NET feature will be so important to you, even as a C# novice, that it actually merits its own chapter: an integrated debugger, which allows you to step through code, observe program run-time behavior, and set breakpoints, even across multiple languages. The debugger is considered in detail in Chapter 10.
In addition to these basic capabilities, VS.NET provides a number of advanced features that will simplify the development process. These features include:
Convenient access to multiple design and code windows
WYSIWYG (What You See Is What You Get) visual design of Windows forms and web forms
An HTML editor which provides both Design and HTML views that update each other in real time
A Solution Explorer, which displays all the files comprising your solution (a collection of projects) in a hierarchical format
A Server Explorer, which allows you to log on to servers to which you have network access, access the data and services on those servers, and perform a variety of other chores
Integrated support for source control software
Many of these advanced features are covered in detail in Programming ASP.NET and Programming .NET Windows Applications (both books cowritten by Jesse Liberty and Dan Hurwitz, published by O’Reilly).
Robert Heinlein said “TANSTAAFL: There ain’t no such thing as a free lunch.”[4] While Visual Studio .NET can save you a lot of grunt typing (and in general greatly facilitate and accelerate the development process), the automatically generated code can obscure what is really necessary to create good working applications. It is sometimes difficult to know how Visual Studio .NET accomplishes its legerdemain. Similarly, the proliferation of mysteriously named files across your filesystem can be disconcerting when all you want to do is a simple housekeeping chore, like rename a minor part of the project.
Since most of the applications we’ll build in this book are console applications designed to illustrate the basics of the language, there will be very little obscuring code produced. When you create Windows and web applications, however, you’ll want to learn to sort through the code Visual Studio .NET generates in order to focus on the logic of your program.
The current chapter cannot possibly teach you everything about Visual Studio .NET; it is far too large and complex an application. What this chapter does is give you the basics for getting started and also point out some of the possible pitfalls.
Tip
Keep in mind that there’s no way to familiarize you with some of these features without wading into some slightly deeper waters of C# programming, which will likely be a bit cloudy to you at this stage. As you get deeper into the book and learn more about the language, your understanding of VS.NET will become clearer.
The Start Page is the first thing you see when you open Visual Studio .NET (unless you configure it otherwise). From here you can create new projects or open a project you worked on in a previous session. You can also find out what is new in .NET, access .NET newsgroups and web sites, search for help online, download useful code, or adjust Visual Studio .NET to your personal requirements. Figure 4-1 shows a typical Start Page.
Along the top of the application window is a set of menus and buttons. These menus and buttons are context-sensitive (i.e., they will change as the current window changes).
Along the left side of the window is a series of links to other resources, such as new developments and events in the .NET community, the MSDN online library, and free sample applications.
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 HelloWorld.cs file you created in Chapter 2 is an example.
A typical Visual Studio .NET application can have a number of other files (e.g., assembly information files, references, icons, data connections, etc.). VS.NET organizes these files into a container called a project.
Visual Studio .NET 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 consist of multiple .dll files called modules.
A solution is a set of one or more related projects. Each time you create a new project, Visual Studio .NET either adds it to an existing solution or creates a new solution.
Solutions are defined within a file named for the solution and have the extension .sln.
Tip
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. Visual Studio .NET also creates a file with the same base name as the .sln file, but with the filename extension .sou (e.g., mySolution.sln and mySolution.sou). The .sou file contains metadata used to customize the IDE.
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 Visual Studio .NET 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.
When you create a new project, you get the New Project dialog box, shown in Figure 4-2.
In the New Project dialog, you select the project type (in the left-hand pane) and the template (in the right). There are a variety of templates for each project type. A template is a file that Visual Studio .NET uses to set up the initial state of your project.
For the examples in this book, you’ll always choose Visual C# Project 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 (any directory you like). At this point, you can also name your project. For the purposes of example, enter the name HelloWorld.
Get Learning C# now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.