15.02.2015 Views

C# 4 and .NET 4

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

384 ❘ ChaPTer 16 visuAl studiO 2010<br />

that ship as libraries of the parts of the application. You might even have a different user interface for<br />

administrators. Each of these parts of the application might be contained in a separate assembly, <strong>and</strong> hence,<br />

they are regarded by Visual Studio as separate projects. However, it is quite likely that you will be coding<br />

these projects in parallel <strong>and</strong> in conjunction with each other. Thus, it is quite useful to be able to edit them<br />

all as one single unit in Visual Studio. Visual Studio allows this by regarding all the projects as forming one<br />

solution <strong>and</strong> by treating the solution as the unit that it reads in <strong>and</strong> allows you to work on.<br />

Up until now, we have been loosely talking about creating a console project. In fact, in the example you<br />

are working on, Visual Studio has actually created a solution for you — although this particular solution<br />

contains just one project. You can see the situation in a window in Visual Studio known as the Solution<br />

Explorer (see Figure 16 - 10), which contains a tree structure that defi nes your solution.<br />

Figure 16 - 10 shows that the project contains your source file, Program.cs ,<br />

as well as another <strong>C#</strong> source file, AssemblyInfo.cs (found in the<br />

Properties folder), which allows you to provide information that<br />

describes the assembly as well as the ability to specify versioning<br />

information. (You look at this file in detail in Chapter 18, “ Assemblies. ” )<br />

The Solution Explorer also indicates the assemblies that your project<br />

references according to namespace. You can see this by exp<strong>and</strong>ing the<br />

References folder in the Solution Explorer.<br />

If you have not changed any of the default settings in Visual Studio, you<br />

will probably fi nd the Solution Explorer in the top - right corner of your<br />

screen. If you cannot see it, just go to the View menu <strong>and</strong> select Solution<br />

Explorer.<br />

The solution is described by a fi le with the extension .sln — in this<br />

figure 16-10<br />

example, it is ConsoleApplication1.sln . The project is described by<br />

various other fi les in the project ’ s main folder. If you attempt to edit these<br />

fi le s u si ng N ot epad , you w i l l fi nd t h at t he y a re mo s t ly pl a i n - t ex t fi le s , a nd , i n ac c ord a nc e w it h t he pr i nc iple<br />

that .<strong>NET</strong> <strong>and</strong> .<strong>NET</strong> tools rely on open st<strong>and</strong>ards wherever possible, they are mostly in XML format.<br />

C++ developers will recognize that a Visual Studio solution corresponds to an old<br />

Visual C++ project workspace (stored in a .dsw fi le), <strong>and</strong> a Visual Studio project<br />

corresponds to an old C++ project (.dsp fi le). By contrast, Visual Basic developers will<br />

recognize that a solution corresponds to an old Visual Basic project group (.vbg fi le),<br />

<strong>and</strong> the .<strong>NET</strong> project corresponds to an old Visual Basic project (.vbp fi le). Visual<br />

Studio differs from the old Visual Basic IDE in that it always creates a solution for<br />

you automatically. In Visual Studio 6, Visual Basic developers would get a project;<br />

however, they would need to request a project group from the IDE separately.<br />

adding another Project to the solution<br />

As you work through the following sections, you will see how Visual Studio works with Windows<br />

applications as well as with console applications. To that end, you create a Windows project called<br />

BasicForm that you will add to your current solution, ConsoleApplication1 .<br />

This means that you will end up with a solution containing a Windows application <strong>and</strong><br />

a console application. That is not a very common scenario — you are more likely to<br />

have one application <strong>and</strong> a number of libraries — but it allows you to see more code!<br />

You might, however, create a solution like this if, for example, you are writing a utility<br />

that you want to run either as a Windows application or as a comm<strong>and</strong>-line utility.<br />

www.it-ebooks.info

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!