Del via


How to: Add a Reference to a Visual Studio Project in a Web Site

A project contains the files that make up your Web site, including pages, configuration files, code files, and binary (compiled code) files. In Visual Studio, you can create multiple projects per solution to address different application requirements. Solution definitions include the dependency relationships among projects. They also include information about how to deploy the projects that make up your solution. Between them, the projects in your solution make up an application.

Keeping projects modularized helps you organize your code better. For example, you might create a component in one project that you want to include in a separate Web site project.

To add a reference to your component project in your Web site solution, you first add the project, and then add a reference to the new project's classes. Only projects that build a DLL can be referenced. Project references are updated automatically when the project builds, whereas assembly references need to be statically updated by the user.

Note

In Visual Web Developer Express Edition, you can have multiple Web site projects in the same solution, but you cannot add client projects to a solution. For an alternative, see Adding References to a Project in a Web Site in Visual Web Developer Express Edition later in this topic.

Adding Projects to a Solution in Visual Studio

You can add either a new project or an existing project to a solution.

To add a new project to a solution

  1. In Solution Explorer, select the solution or the solution folder that you want to add a project to.

  2. On the File menu, choose Add, and then choose New Project.

  3. Select a project type and template and then click OK.

You can add an existing project to a solution and then edit that project to meet the requirements of the current solution. However, this changes the project settings of the project in the original location.

To add an existing project to a solution

  1. In Solution Explorer, select the solution or the solution folder that you want to add a project to.

  2. On the File menu, choose Add and then choose Existing Project.

  3. Select the project you want to add to the solution and then click Open.

Adding a Project Reference to a Web Site in Visual Studio

After you have added a project to your solution, you can reference the project from your Web site project.

To reference another project in a Web site

  1. In Solution Explorer, select the Web site project that you want to add the project reference to.

  2. On the Website menu, choose Add Reference. Alternatively, you can right-click your Web site project and then click Add Reference.

    The Add Reference dialog box is displayed.

  3. Click the Projects tab.

  4. From the list of available projects, select the one to which you want a reference and then click OK.

    The following are added to your Web site's Bin folder:

    • A copy of the assembly created from the added project.

    • Copies of dependent assemblies, XML document files, license files, resource files, and so on.

    • The program database (.pdb) file, which holds debugging and project state information for the debug version of the added assembly. This file is copied if present in the original location, regardless of the build settings.

Adding References to a Project in a Web Site in Visual Web Developer Express Edition

In Visual Web Developer Express Edition, you can have many Web site projects in the same solution, but you can not add client projects to a solution. Therefore, you cannot populate the Projects tab of the Add Reference dialog box. However, you can add the assembly DLL or the source code file to your Web site project manually.

To add an assembly DLL to your Web site project

  1. In Solution Explorer, select your Web site.

  2. On the Website menu, choose Add Reference. Alternatively, you can right-click the name of your Web site and then select Add Reference.

    The Add Reference dialog box is displayed.

  3. Select the Browse tab.

  4. Navigate to the folder containing the assembly you want to reference, select the assembly, and then click OK.

    Adding a reference in this way ensures that all file dependencies (debug files, XML document files, and so on) are copied.

To add a source code file to your Web site project

  1. If your Web site does not already contain an App_Code folder under the Web site root, in Solution Explorer, right-click the name of your Web site, click Add ASP.NET Folder, and then click App_Code Folder. For more information about special folders, see Shared Code Folders in ASP.NET Web Sites.

  2. In Solution Explorer, select your Web site's App_Code folder.

  3. On the Website menu, click Add Existing Item.

    The Add Existing Item dialog box is displayed.

  4. In the Files of type dropdown list, select Class Files.

  5. Browse to the project you want to add, select the source code file, and then click Add.

    A static copy of the selected file is added to your project. These copies are not automatically updated. You can now use the classes in the source code file in your Web site files. Files in the App_Code folder are compiled at run-time.

See Also

Tasks

How to: Create Multi-Project Solutions

Reference

Add Reference Dialog Box

Add New Project Dialog Box