Web application project and website project

Source: Internet
Author: User

Http://msdn.microsoft.com/zh-cn/library/dd547590.aspx

In Visual Studio, you can create a web application project or website project ". Each type has its own advantages and disadvantages. You must know the differences between them before you can select the best type. Before creating a project, it is very important to select an appropriate project type because it is not easy to switch from one project type to another.

Description

In some cases, you cannot select. For example, to create an ASP. net mvc application, you must use a web application project.

This topic contains the following sections:

  • Solution

  • Difference Summary

  • Project file structure

  • Compile

  • Deployment

Solution

The main factor for selecting between a web application project and a website project is how you plan to deploy the project and how you want to maintain the project after the project is deployed. Web application projects with priority options include:

  • You want to use msbuild to compile the project. For example, you may want to add pre-jobs and post-Build Steps.

  • You want the compiler to create a single assembly for the entire site.

  • You need to control the name and version number of the Assembly generated for the site.

  • You want to reference the code hidden classes of pages and user controls from independent classes.

  • You want to establish project relevance between multiple web projects.

Website projects with priority options include:

  • You want to update each file in production by simply copying the new version to the production server or directly editing the file on the production server.

  • You do not want to explicitly compile the project with the release configuration to deploy the project.

  • You want the compiler to create multiple assemblies for the site. It can be an assembly for each page or user control, or one or more assemblies for each folder.

Difference Summary

The following table summarizes the main differences.

Region

Web Application Project

Website project

Project file structure

The Visual Studio project file (. csproj or. vbproj) stores information about the project, such as the file list contained in the project and any reference between the projects.

The project file (. csproj or. vbproj) does not exist ). All files in the folder structure are automatically included in the site.

Compile

  • Explicitly compile the source code on the computer used for development or source code control.

  • By default, an assembly is generated when you compile a code file (excluding the. aspx and. ascx files.

  • The source code is usually compiled on the server through ASP. NET Dynamic (automatic) When a request is received for the first time after the site is installed or updated.

    You can pre-compile the site (pre-compile on the development computer or server ).

  • By default, multiple assemblies are generated during compilation.

Namespace

By default, an explicit namespace is added to pages, controls, and classes.

By default, explicit namespaces are not added to pages, controls, and classes, but you can manually add them.

Deployment

  • Copy the assembly to the server. The Assembly is generated by compiling the application.

  • Visual Studio provides multiple tools integrated with IIS Web deployment tools to automatically execute many deployment tasks.

  • Copy the application source file to the computer where IIS is installed.

  • If you pre-compile the site on the development computer, you can copy the Assembly generated by compilation to the IIS server.

  • Visual Studio provides multiple deployment tools, but these tools do not automatically run as many deployment tasks as they are for Web application projects.

Project file structure

Web application projects use Visual Studio project files (. csproj or. vbproj) to track information about projects. In addition to other tasks, this also makes it possible to specify which files are to be included or excluded in the project, and which files are compiled during generation.

For website projects, all files in the folder structure are automatically considered to be included in the website. If you want to exclude certain files from compilation, you must remove files from the website project folder or change their file extensions to extensions not compiled and provided by IIS.

Using project files in a web application project has the following advantages:

  • It is easy to temporarily remove files from the site, but still ensure that they are not lost because these files are kept in the folder structure. For example, if the page is not ready for deployment, You can temporarily exclude it from creation without deleting it from the folder structure. You can deploy the compiled assembly and then include the file in the project again. This is especially important when you use source code to manage the repository.

Using a folder structure without project files in a website project has the following advantages:

  • You do not have to manage the project structure in Visual Studio. For example, you can use Windows Resource Manager to copy files to a project or delete files from a project.

Compile

For Web application projects, a project is usually generated in Visual Studio, or a project is generated by using an ASP. NET batch processing compiler on a computer that is not a production IIS server. All the code hiding class files and independent class files in the project are compiled into an assembly and placed in the bin folder of the Web application project. (The. aspx and. ascx files are dynamically compiled in a way similar to the website project .)

For website projects, you do not have to manually compile the project. Website projects are usually dynamically compiled by ASP. NET (on Development computers and production IIS servers. You can select between the batch compilation mode (usually one assembly is generated for each folder) and the fixed compilation mode (usually one assembly is generated for each page or user control.

The compilation model of Web application projects has the following advantages:

  • You can use msbuild to create a custom batch compilation process.

  • It is very easy to specify Assembly features (such as names and versions.

  • Pre-compilation ensures that users do not have to wait during site compilation on the production server. (If the site is very large, dynamic compilation of website projects may take a lot of time. Dynamic compilation occurs when a site resource request is received after the site is updated. when resources are compiled, the compilation request may be delayed. If the latency is unacceptable, You can pre-compile the site. But it will lose some advantages of dynamic compilation .)

  • You can have full control over the location of code files in the project folder structure, and the way classes in the project reference each other. (Dynamic compilation requires that the source code of all classes used in the entire site must be in the app_code folder. You cannot reference a page or user control class from the class in app_code .)

  • Visual Studio code analysis is applicable to Web application projects, but not website projects.

The website project compilation model has the following advantages:

  • You can test a specific page regardless of the status of other pages. This is because you do not need to compile the entire site to run a single page. You only need to compile the page and any components that the page depends on, such as the code in the app_code folder or the Global. asax file. (In a web application project, if there is a compilation error at any location in the site, you cannot create an assembly, so you cannot perform a test, or even part of the content of the site compiled by the test .)

  • It is very easy to update websites in production. You can update various source code files on the production server without explicitly recompiling the site. Even if other files are not ready due to compilation errors, you can update each file that is ready for deployment. You can also directly open a website on the Production IIS server in Visual Studio and update the website in real time.

  • In some cases, precompiled multi-assembly has a performance advantage. A typical example is a website with many pages and a lot of code for these pages. Most pages are rarely requested, and only some pages are frequently used. If such a site is compiled into multiple assemblies, the production server can load only the Assemblies required for the current request. If a page is not requested, the corresponding assembly is not loaded.

Description

There is no performance difference between a website project and a web application project. The only obvious exceptions are those that have already been pointed out. In actual use, they are only applicable to very large sites. The first request to the website may need to be compiled, which may lead to latency. If the website runs on an IIS server with insufficient memory, the memory used to include the entire site in an assembly may exceed the memory required to include the site in multiple datasets.

Deployment

To deploy a web application project, copy the Assembly created by compiling the project to the IIS server. To deploy a website project, the project source file is usually copied to the IIS server.

Web application project deployment policies have the following advantages:

  • You can avoid deploying source code to the IIS server. In some cases, for example, in a shared bearer environment, you may be concerned with unauthorized access to the source code on the IIS server. (For website projects, this risk may be avoided by pre-compiling on the development computer and deploying the generated Assembly instead of the source code. However, in this case, some benefits of easily updating the site will be lost .)

  • In addition to copying an assembly or code to the server, deployment usually involves other tasks. For example, the database script may have to run in production, and the connection string in the web. config file may need to be changed for the production server. Visual Studio provides tools for processing web application projects to automatically execute many of these tasks, such as one-click release. These tools are not available for website projects.

Website project deployment policies have the following advantages:

  • If you make a few changes to the web application, you do not have to redeploy the entire application. Instead, you can only copy the changed files to the production IIS server. In addition, you can directly edit files on the production server. (Because the code file of the Web application project will be compiled into a single assembly file, the entire site must be deployed even if a few changes are made, unless the changes are only. aspx or. ascx file .)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.