• Project-based development
When you create a web project, Visual Studio generates a number of extra files project file
|
.csproj |
project file |
records the files in your project and stores a few debugging settings |
|
.csproj.user |
project file |
|
|
.sln |
solution file |
|
When you build your application, Visual Studio generates
|
temporary files |
in the Obj subdirectory |
|
None of these files should be deployed to the web server when your web application is complete |
|
one or more .pdb files |
in the Bin subdirectory |
debugging symbols |
When you run a web project, Visual Studio compiles all your code into a single assembly before launching your web browser.
• Projectless development
An alternate approach is to create a simple website without any project file. In this case, Visual Studio assumes that every file in the website directory (and its subdirectories) is part of your web application. In this scenario, Visual Studio doesn’t need to precompile your code. Instead, ASP.NET compiles your website the first time you request a page. (Of course, you can use precompilation to remove the first-request overhead for a deployed web application. Chapter 18 explains how.)
■The most significant advantages of web projects
|
stricter |
This is because the project file explicitly lists what files should be part of the project. This allows you to catch potential errors (such as missing files) and even deliberate acts of sabotage (such as unwanted files added by a malicious user) |
|
more flexible file management |
One example is if you’ve created several separate projects and placed them in subdirectories of the same virtual directory. In this case, the projects are kept separate for development purposes but are in essence the same application for deployment. With projectless development, there’s no way to keep the files in these subdirectories separate. |
|
more efficient with a huge number of resource files |
for example, a website that includes an Images subdirectory with thousands of pictures. With projectless development, Visual Studio examines these files and adds them to the Solution Explorer, because they’re a part of your website directory. But a web project avoids this extra overhead because you won’t explicitly add the images to the list of files in your project. |
|
customizable deployment |
Visual Studio project files work with the MSBuild utility, which allows project compilation to be automated and customized. Also, you get more control over the generated assembly for your web application, which you can name appropriately, sign, and so on。 |
|
work better in migration |
For this reason, ASP.NET automatically converts Visual Studio .NET 2003 web projects to Visual Studio 2008 web projects. This conversion requires fewer changes to your pages. |
■precompilation
At first glance, the precompilation of web projects seems like a big win—not only does it ensure pages don’t need to be compiled the first time they’re requested, but it also allows you to avoid deploying your source code to the web server. However, projectless websites can be compiled for deployment just as easily—yousimply need to use the precompilation tool you’ll learn about in Chapter 18.
■Choose
Both projectless and project-based development give you all the same ASP.NET features. Both approaches also offer the same performance. So which option is best when building a new ASP.NETwebsite?
There are advocates for both approaches. Officially, Microsoft suggests you use the simpler website model unless there’s a specific reason to use a web project—for example, you’ve developed a custom MSBuild extension, you have a highly automated deployment process in place, you’remigrating an older website created in Visual Studio 2003, or you want to create multiple projects in one directory.
浙公网安备 33010602011771号