Home  >  Article  >  Backend Development  >  What is the difference between creating a new website and a new WEB project in VS?

What is the difference between creating a new website and a new WEB project in VS?

巴扎黑
巴扎黑Original
2017-04-30 10:43:564698browse

Advantages of the WebApplication programming model

●The website is compiled quickly, using the incremental compilation mode. Only after the file is modified, this part will be incrementally compiled.

●Generated assembly
WebSite: Generate a random assembly name. You need to use the plug-in WebDeployment to generate a single assembly
WebApplication: You can specify a website project to generate a single assembly. Because it is an independent assembly, you can specify the name, version, output location and other information of the application assembly just like other projects

●The website can be split into multiple projects for easier management

●A file can be excluded from the project and source code management

●Conveniently supports Team Build of VSTS for daily building

●More powerful code inspection function, and the inspection strategy is controlled by source code

●You can perform your own prescribed processing before and after compilation

●Strong Resource class support for App_GlobalResources (it’s mentioned online, but I haven’t learned about it yet)

●Directly upgrade large-scale systems built using VS2003

Advantages of the WebSite programming model

●Compile the page dynamically and you can see the effect immediately without compiling the entire site (main advantage)

●Same as above, you can prevent the wrong part from interfering with the used part (you can require that you can check in only after the compilation passes)

●You can generate an assembly for each page (this method is generally not used)

●You can treat a directory as a Web application, copy the files directly and publish them without project files (suitable for small sites)

●The page can also be compiled into the assembly (should not be used, and WebApplication can also be implemented through the WebDeployment plug-in)

Conversion between two programming models

VS2005 SP1 has a built-in conversion program, which can easily convert from WebSite to WebApplication
Just copy the file, right-click and execute "Convert to Web Application".

I haven't found any special reverse conversion tool, but after comparison, I found that the conversion is very simple.
Delete all *.designer.cs
Batch replace Codebehind="******.aspx.cs" in *.aspx, *.ascx, *.master page files with CodeFile="******.aspx.cs"

This way you can convert it back

#

Scenario

Web Application Project

Web Site Project

Project definition

Similar to Visual Studio .NET 2003 , due to the existence of the project file, only the files referenced by the project file will be in Solution Explorer## Appears in #. And only these files will be compiled. You can easily split an ASP.NET application into multiple Visual Studio projects. It is easy to exclude a file from the project and source code control.

A directory structure is a WEB project. No project file exists. All files in this directory exist as part of the project. Of course, for a website we actually deploy, there will be no project files on the deployment. If you want to modify the website, this programming model is very suitable. We don't need to care at all about which project those files belong to in this
WEB site.

Compile and generate

The Web application project compilation mode is almost the same as that of Visual Studio .NET 2003.

All code-behind class files and independent class files in the project are compiled into an independent application assembly. This application set is placed in the Bin directory. Because it is an independent application set, you can specify the name, version, output location and other information of the application set.

For example: Model-View-Controller (MVC) The pattern can be used very well here. Because it allows an independent class to be referenced in WEB pages and WEB user controls.

The compile (

Build) command is just to test whether the WEB site is compiled correctly and to debug a WEBWhen it comes to site projects, it is achieved by dynamically compiling pages and classes relying on your source code files, ASP.net.

Precompiled sites and dynamically compiled sites use the same compilation semantics . You can improve the performance of your site through precompilation.

ASP.net The dynamic compilation system provides two models: the default batch compilation model and fixed-names Compile model.

batch In the compilation model, it is compiled into multiple application sets (typically each directory is compiled into one). At this time, when you look at the application set, it is difficult to determine which directory it is.

fixed-names In the compilation model, each page of the website or each user control is compiled into an application set.

Iterative
development

When debugging or running a Web page, you must compile the entire WEB project.

Compiling the entire WEB project is usually faster because Visual Studio uses incremental compilation mode, only the files are modified Only then will this part be incrementally compiled.

You can configure the compilation properties of Visual Studio 2005: compile the entire site, compile a specific page, or do nothing. In the last case, when you run a WEB site, Visual Studio only opens a browser and accesses The current or starting page, when this request is sent, ASP.net starts dynamic compilation.

In this mode, the page is dynamically compiled or compiled into different application sets, so if you debug or run a page, the entire project does not need to be compiled. The part with errors and the part you use can not interfere with each other.

By default, when you run or debug any WEB page, Visual Studiofully compilesWeb Site project.

You can see all errors during compilation by doing this. However, during development, fully compiling the entire site can be quite slow. Therefore, it is recommended that you only compile the current page during development and debugging.

Deployment

Because all class files are compiled into an application assembly, when you deploy, you only need to combine this application assembly with the .aspx file, .ascx files are deployed together with other static content files.

Under this model, the .aspx file will not be compiled. It will be dynamically compiled when the browser accesses this page.

However, if you use Web Deployment Projects (a Visual Studio 2005 plugin, it is not included by default VS2005),You can also compile the .aspx file into an application Program concentration.

If you only modify a small line of code, you also need to compile all the code of the entire project and publish the application set containing all the code.

Using the ##Publish Website command of Visual Studio , you can put .aspx files and code-behind files are compiled into the application assembly, so you see the compiled .aspx The file header has changed. (Note: The Build command does not give you the set of deployable applications)

The latest version of Publish will support compiling only code-behind files, so that when deployed, it will not change .aspx file.

The default is to precompile several application sets in the Bin directory. Typically, one directory corresponds to one application set.

fixed-names Deployment options allow each WEB page or each WEB user control Create an application set so that each page has a deployable application set. However, the fixed-names deployment option will increase the number of application sets and the actual memory usage will also increase.

Upgrade fromVisual Studio .NET 2003

Because it uses the same WEB project development model as VS2003, the upgrade is very, very simple.

Web site The different compilation options of the project lead to great differences between it and the Visual Studio .NET 2003WEB project.

Although Microsoft provides a conversion wizard, if your project is a complex VS2003 project, after using this conversion wizard, you still need to refer to the conversion manual and do lots of work.

If you want to upgrade from VS2003, it is recommended not to use this WEB site development template. Instead use the Web application project.

Which WEB programming model to choose

Option or Task

Web Application Projects

Web Site Projects

You have a large Visual Studio .NET 2003 Web application that needs to be migrated to VS2005.

 

Like to use the single-page code model to develop website pages. Instead of using the code-behind model to write website pages

 

I like to write websites in the following way:

 

When writing a page, in order to quickly see the writing effect, dynamically compile the page, and you can see the effect immediately without compiling the entire site.

(That is to say, you only need to save the file and refresh it in the browser to see the effect you just made)

Need to control the name of the compiled application assembly

 

Need to generate an application set per page

 

A separate class needs to be used in the WEB page or WEB user control.

 

You need to use multiple Project to build a Web application.

 

Need to handle pre-build and post-build events (need to have its own additional processing before and after compilation)

 

I hope to treat a directory as a WEB application without the need to create a new Project file.

 

The above is the detailed content of What is the difference between creating a new website and a new WEB project in VS?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:About aspx.designer.csNext article:About aspx.designer.cs