15.2. Projects and Solutions


Visual Studio .NET uses projects and solutions to organize your applications. A project contains user interface and source files, as well as other files such as data sources and graphics. Typically, the contents of a project are compiled into an assembly, e.g., an executable file (.exe) or a dynamic link library file (DLL).

You can create many types of projects in Visual Studio 2005, including:

  • Windows application

  • Windows service

  • Windows Control Libray

  • Web Control Library

  • Class Library

  • Pocket PC templates

  • SmartPhone templates

  • Windows CE templates

  • Crystal Reports Windows application

  • SQL Server project

  • Word and Excel document and template

  • Screen saver

15.2.1. Templates

When you create a new project by clicking the New Project... link on the Start Page or File New Project ..., you get the New Project dialog box , as shown in Figure 15-3.

Figure 15-3. New Project dialog box


As described in the "Web Sites" section, web applications are not created by creating a new project, but by creating a new web site.


To create a new project, you select a project type and a template. There are a variety of templates for each project type. For example, the templates for Visual Basic 2005 Projects, shown in Figure 15-3, are different from the templates available to Other Project Types Setup and Deployment. By selecting a Visual Studio Solutions project type, you can create an empty solution, ready to receive whatever items you want to add.

The template controls what items will be created automatically and included in the project, as well as default project settings. For example, if your project is a Visual Basic 2005 Web application, then web forms (.aspx) files and language-specific code-behind (.vb) files will be created as part of the project. If a different template is selected, then an entirely different set of files will be created.

15.2.2. Web Sites

A typical .NET web application is comprised of many items: content files (e.g., .aspx files), source files (e.g. .vb files), assemblies (e.g. .exe and .dll files) and assembly information files, data sources, references, and icons, as well as miscellaneous other files and folders. Visual Studio 2005 organizes these items into a folder that represents the web site. The web site folder is housed in a solution. When you create a new web site, Visual Studio 2005 automatically creates the solution.

To create a new web application, either click on New Web Site ... from the Getting Started box on the Start Page, or go to File New Web Site ... In either case, you will get the New Web Site dialog box, as shown in Figure 15-4. It will present lists of available templates, described shortly.

Figure 15-4. New Web Site


Below the list of templates are a set of controls for setting the location and language for your web site.

The first drop down, Location, allows you to work on web applications in three different manners, from three different types of locations. The choice here controls much more than just a physical location.


File System

The default, causes the new web site folder to be created somewhere on the physical file system accessible to this PC and this user, either on the local machine or the network.

The Browse ... button and associated drop-down list allow you to browse the file system, and select any desired folder.

Choosing File System causes Visual Studio 2005 to run the web application using its own internal web server, rather than IIS. A persistent virtual directory for the web application is not created, and IIS is not part of the picture. In fact, IIS is not even required to be installed on the the development machine. (Of course, IIS is required on any deployment servers.)

The downside to using File System as the Location is that web pages created this way cannot be run from a browser, only through Visual Studio 2005 (since there is no virtual directory to reference after "localhost" in the browser address box). This is true even when redirecting users to another page programatically with the Response.Redirect or Server.Response methods. A URL such as http://localhost/myWebApp/default.aspx referencing the target web site will not work unless you manually create a virtual directory called myWebApp in Computer Management on the local machine (right-click on My Computer and select Manage, then drill down to Services and Applications Internet Information Services Web Sites Default Web Site, then right-click and select New Virtual Directory ...).

The advantage, however, is that it is very easy to share file-based solutions: you just copy the entire directory to the new machine and open it in Visual Studio. This will be the preferred approach for this book.


HTTP

This selection implies that IIS will be serving the pages. As such, it requires that the web application be located in an IIS virtual directory. Visual Studio 2005 will automatically create this virtual directory. This is evident when you open a browser on the local machine and enter a URL such as that shown in the previous description, which will now work fine.

The Browse ... button and associated drop-down list allow you to browse and select from the contents, especially the virtual directories, on IIS running either locally or remotely (use the buttons on the left side of the dialog box to choose).

You can also see any virtual directories created by Visual Studio 2005 by opening Computer Management and looking under Default Web Site.


FTP

This selection allows you to develop your web site on a remote location accessible via the FTP protocol. You will be presented with an FTP Log On dialog box with a checkbox to allow Anonymous Log in, and textboxes for login user name and password, if necessary.

The Browse ... button and associated drop-down list allows you to enter the information necessary to log in to an FTP site.

15.2.3. Solutions

Solutions typically contain one or more projects and/or web sites. They may contain other, independent items as well. These independent solution items are not specific to any particular project, but apply, or scope, to the entire solution. The solution items are not an integral part of the application, because they can be removed without changing the compiled output. They display in Solution explorer (described later in this chapter) in a Solution Items folder, and can be managed with source control.

Miscellaneous files are independent of the solution or project, but they may be useful to have handy. They are not included in any build or compile, but will display in the Solution explorer and may be edited from there. Typical miscellaneous files include project notes, database schemas, or sample code files. To display the Miscellaneous Files folder as part of the solution, go to Tools Options Environment Documents, and check the checkbox for Show Miscellaneous Files in Solution explorer.

It is also possible to have a solution that does not contain any projects just solution items or miscellaneous files , which can be edited using Visual Studio 2005.

Solutions are defined by a solution file, created by Visual Studio 2005 and named for the solution with a .sln extension. The .sln file contains a list of the projects that comprise the solution, the location of any solution-scoped items, and any solution-scoped build configurations. Visual Studio 2005 also creates a .suo file with the same name as the .sln file (e.g., mySolution.sln and mySolution.suo). The .suo file contains data used to customize the IDE on a per-user and per-solution basis.

In previous versions of Visual Studio, the .suo file was maintained only on a per-solution, not per-developer basis.


The solution file is placed in the Visual Studio projects location. By default it will look like the following (with your user name substituted):

     c:\Documents and Settings\username\My Documents\Visual Studio\Projects 

However, you can change it to something a little easier to navigate, such as:

     c:\vsProjects 

by going to Tools Options Projects and Solutions General.

You can open a solution in Visual Studio 2005 by double-clicking the .sln file in Windows Explorer. Even if the .sln file is missing, you can still open a project in Visual Studio 2005. A new .sln file will be created when you save.

There is no project file, but there is a project folder. There are no solution folders, but there is a solution file that lives in a project folder. A solution file may reference multiple projects, including projects from other project folders.

Furthermore, the Solution explorer in Visual Studio 2005 (described in the following section) displays projects as though they are contained within solutions, even though the physical directory structure does not support this interpretation.

This can be a bit confusing, but it all comes together and works well enough once you get used to it.




Programming Visual Basic 2005
Programming Visual Basic 2005
ISBN: 0596009496
EAN: 2147483647
Year: 2006
Pages: 162
Authors: Jesse Liberty

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net