Compartilhar via


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

To add a reference to a component project in a Visual Studio solution, you first add the project, and then you add a reference to the new project's classes. Only projects that contain code and build a DLL can be referenced. (For example, a project that contains only resource or image files cannot be referenced.) Project references are updated automatically when the project builds, whereas references to .NET or COM components need to be updated manually. For more information, see How to: Add a Component Reference to a Visual Studio Web Project.

Note

In Visual Web Developer Express, you can have multiple Web site projects in the same solution, but you cannot add component projects to a solution. For an alternative, see Adding References to a Project in a Web Site in Visual Web Developer Express 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 that you want to add a project to. (If you do not see the solution in Solution Explorer, select Options from the Tools menu, click Projects and Solutions, and then click Always show solution.

  2. In 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 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 in Visual Studio

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

To reference another project

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

  2. On the Website menu (for Web site projects) or the Project menu (for Web application projects), choose Add Reference. Alternatively, you can right-click your Web project in Solution Explorer 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 to add a reference and then click OK.

    The following are added to your Web project'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

In Visual Web Developer Express, you can have many Web projects in the same solution, but you cannot add other types of projects such as class library 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 that is generated by a project from another solution to your Web project manually.

To add an assembly DLL to your Web site project

  1. In Solution Explorer, select your Web project.

  2. On the Website menu (for Web site projects) or the Project menu (for Web application projects), choose Add Reference. Alternatively, you can right-click the name of your Web project in Solution Explorer and then select Add Reference.

    The Add Reference dialog box is displayed.

  3. Select the Browse tab.

  4. Browse to the folder that contains 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 project does not already contain an App_Code folder under the Web site root, in Solution Explorer, right-click the name of the project, 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 Site Projects.

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

  3. On the Website menu (for Web site projects) or the Project menu (for Web application projects), 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 folder that contains the source code file that you want to add, select the file, and then click Add.

    A static copy of the selected file is added to your project. This copy is not automatically updated when the file in the folder you added it from is changed. 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

Other Resources

ASP.NET Web Projects

Web Application Projects versus Web Site Projects in Visual Studio