Visual Studio Also Upload Code Behind Files
This browser is no longer supported.
Upgrade to Microsoft Border to take advantage of the latest features, security updates, and technical back up.
Determining What Files Need to Be Deployed (C#)
by Scott Mitchell
Download Lawmaking or Download PDF
What files need to be deployed from the development environs to the production surround depends in part on whether the ASP.NET application was built using the Spider web Site Model or Spider web Application Model. Learn more about these two project models and how the project model affects deployment.
Introduction
Deploying an ASP.Internet web awarding entails copying the ASP.NET-related files from the development surround to the production environs. The ASP.Internet-related files include ASP.NET spider web folio markup and lawmaking and client- and server-side support files. Customer-side support files are those files referenced by your spider web pages and sent directly to the browser - images, CSS files and JavaScript files, for example. Server-side support files include those that are used to process a asking on the server-side. This includes configuration files, web services, grade files, Typed DataSets, and LINQ to SQL files, among others.
In full general, all client-side support files should be copied from the development environment to the product environment, but what server-side support files go copied depends on whether yous are explicitly compiling the server-side code into an assembly (a .dll
file) or if you are having these assemblies machine-generated. This tutorial highlights what files need to exist deployed when explicitly compiling the code into an assembly versus having this compilation stride occur automatically.
Explicit Compilation Versus Automatic Compilation
ASP.NET web pages are divided into declarative markup and source code. The declarative markup portion includes HTML, Web controls, and databinding syntax; the code portion contains event handlers written in Visual Basic or C# code. The markup and code portions are typically separated into different files: WebPage.aspx
contains the declarative markup while WebPage.aspx.cs
houses the code.
Consider an ASP.Internet page named Clock.aspx that contains a Label control whose Text holding is gear up to the current engagement and time when the page loads. The declarative markup portion (in Clock.aspx
) would incorporate the markup for a Label Web control -<asp:Characterization runat="server" id="TimeLabel" />
- while the code portion (in Clock.aspx.cs
) would have a Page_Load
event handler with the following code:
protected void Page_Load(object sender, EventArgs e) { TimeLabel.Text = "The time at the beep is: " + DateTime.Now.ToString(); }
In order for the ASP.NET engine to service a request for this page, the page's lawmaking portion (the WebPage.aspx.cs
file) must get-go be compiled. This compilation can happen explicitly or automatically.
If the compilation happens explicitly then the entire application's source code is compiled into one or more assemblies (.dll
files) located in the application's Bin
directory. If the compilation happens automatically then the resulting automobile-generated associates is, by default, placed in the Temporary ASP.NET
Files folder, which tin can be found at %WINDOWS%\Microsoft.Internet\Framework\
<version>, although this location is configurable via the <compilation>
element in Web.config
. With explicit compilation you must take some activeness to compile the ASP.Net application's code into an assembly, and this step occurs prior to deployment. With automated compilation the compilation process occurs on the web server when the resource is first accessed.
Regardless of what compilation model you use, the markup portion of all ASP.NET pages (the WebPage.aspx
files) need to be copied to the production environs. With explicit compilation you need to re-create up the assemblies in the Bin
binder, but yous do not need to copy up the ASP.Net pages' lawmaking portions (the WebPage.aspx.cs
files). With automatic compilation you need to copy up the code portion files then that the code is nowadays and can be compiled automatically when the page is visited. The markup portion of each ASP.NET spider web page includes a @Page
directive with attributes that indicate whether the page'due south associated code was already explicitly compiled or whether it needs to be automatically compiled. Every bit a effect, the production environs can work with either compilation model seamlessly and you lot do not demand to apply any special configuration settings to signal that explicit or automatic compilation is used.
Table 1 summarizes the different files to deploy when using explicit compilation versus automatic compilation. Notation that regardless of the compilation model used y'all should e'er deploy the assemblies in the Bin
binder, if that folder exists. The Bin
folder contains the assemblies specific to the web application, which include the compiled source code when using the explicit compilation model. The Bin
directory too contains assemblies from other projects and any open up-source or 3rd-party assemblies you lot may be using, and these need to be on the production server. Therefore, as a general rule of pollex, copy the Bin
folder up to production when deploying. (If y'all are using the automatic compilation model and are not using whatsoever external assemblies and so you won't accept a Bin
directory - that's OK!)
Compilation Model | Deploy Markup Portion File? | Deploy Source Code File? | Deploy Assemblies in Bin Directory? |
---|---|---|---|
Explicit Compilation | Yes | No | Yes |
Automatic Compilation | Yeah | Aye | Yeah (if it exists) |
Table one: What files you deploy depends on the compilation model used.
Taking a Trip Down Memory Lane
What compilation approach is used depends, in office, on how the ASP.Cyberspace application is managed in Visual Studio. Since .Cyberspace'due south inception in the year 2000 there have been four different versions of Visual Studio - Visual Studio .NET 2002, Visual Studio .Internet 2003, Visual Studio 2005, and Visual Studio 2008. Visual Studio .Cyberspace 2002 and 2003 managed ASP.NET applications using the Web Application Project model. The key features of the Web Awarding Project model are:
- The files that makeup the project are defined in a single projection file. Any files not divers in the projection file are non considered part of the web application past Visual Studio.
- Uses explicit compilation. Building the project compiles the lawmaking files within the project into a unmarried associates that is placed in the
Bin
binder.
When Microsoft released Visual Studio 2005 they dropped support for the Spider web Application Project model and replaced information technology with the Web Site Projection model. The Web Site Projection model differentiated itself from the Web Application Project model in the post-obit ways:
- Rather than having a single projection file that spells out the project'due south files, the file system is used instead. In short, any files within the web awarding folder (or subfolders) are considered part of the project.
- Building a project in Visual Studio does non create an assembly in the
Bin
directory. Instead, edifice a Web Site Projection reports any compile-time errors. - Support for automatic compilation. Web Site Projects are typically deployed by copying the markup and source code to the production environment, although the code can be precompiled (explicit compilation).
Microsoft revived the Web Awarding Project model when information technology released Visual Studio 2005 Service Pack 1. Nonetheless, Visual Spider web Developer connected to only support the Web Site Project model. The good news is that this limitation was dropped with Visual Web Developer 2008 Service Pack 1. Today you lot tin can create ASP.Cyberspace applications in Visual Studio (and Visual Web Programmer) using either the Web Application Project model or the Web Site Project model. Both models take their pros and cons. Refer to Introduction to Web Application Projects: Comparison Spider web Site Projects and Spider web Application Projects for a comparing of the ii models and to help determine what projection model works all-time for your situation.
Exploring the Sample Web Application
The download for this tutorial includes an ASP.NET application called Book Reviews. The website mimics a hobby website someone might create to share their book reviews with the online community. This ASP.NET web awarding is very unproblematic and consists of the following resources:
-
Web.config
, the application'southward configuration file. -
A master page (
Site.master
). -
Seven different ASP.Net pages:
-
~
/Default.aspx
- the site's homepage. -
~
/About.aspx
- an "Most the Site" page. -
~
/Fiction/Default.aspx
- a page listing the fiction books that take been reviewed.- ~
/Fiction/Blaze.aspx
- a review of the Richard Bachman novel Blaze.
- ~
-
~/
Tech/Default.aspx
- a page listing the technology books that have been reviewed.- ~/
Tech/CYOW.aspx
- a review of Create Your Own Website. - ~/
Tech/TYASP35.aspx
- a review of Teach Yourself ASP.NET iii.5 in 24 Hours.
- ~/
-
-
Three different CSS files in the Styles folder.
-
Four image files - a Powered by ASP.Cyberspace logo and images of the covers of the three reviewed books - all located in the
Images
folder. -
A
Web.sitemap
file, which defines the site map and is used to brandish menus in theDefault.aspx
pages in the root directory andFiction
andTech
folders. -
A class file named
BasePage.cs
that defines a basePage
form. This class extends the functionality of thePage
form past automatically setting theTitle
property based on the page's position in the site map. In a nutshell, whatsoever ASP.NET lawmaking-behind class that extendsBasePage
(instead ofOrganization.Web.UI.Page
) volition have its title set to a value depending on its position in the site map. For case, when viewing the ~/Tech/CYOW.aspx
folio, the title is gear up to "Habitation : Engineering : Create Your Own Website".
Figure 1 shows a screen shot of the Book Reviews website when viewed through a browser. Here you see the page ~/Tech/TYASP35.aspx
, which reviews the volume Teach Yourself ASP.NET iii.five in 24 Hours. The breadcrumb that spans the top of the page and the menu in the left column are based on the site map structure divers in Spider web.sitemap
. The epitome in the right upper corner is one of the book cover images located in the Images
binder. The website'south look and feel are defined via cascading manner sheet rules spelled out by the CSS files in the Styles folder, while the overarching page layout is defined in the master page, Site.master
.
Effigy one: The Book Reviews website offers reviews on an assortment of titles (Click to view total-size image)
This awarding does not use a database; each review is implemented as a separate web page in the application. This tutorial (and the next several tutorials) walk through deploying a web application that does not accept a database. Yet, in a hereafter tutorial we will raise this application to store reviews, reader comments, and other data within a database, and will explore what steps need to exist performed to correctly deploy a data-driven web application.
Notation
These tutorials focus on hosting ASP.Internet applications with a web host provider and do not explore ancillary topics like ASP.NET's site map system or using a base Page
class. For more than information on these technologies, and for more background on other topics covered throughout the tutorial, refer to the Further Reading department at the finish of each tutorial.
This tutorial's download has two copies of the web application, each implemented every bit a different Visual Studio project type: BookReviewsWAP, a Web Awarding Project, and BookReviewsWSP, a Web Site Project. Both projects were created with Visual Web Developer 2008 SP1 and use ASP.NET iii.5 SP1. To piece of work with these projects start by unzipping the contents to your Desktop. To open up the Web Application Projection (BookReviewsWAP), navigate to the BookReviewsWAP folder and double-click the Solution file, BookReviewsWAP.sln
. To open the Web Site Project (BookReviewsWSP), launch Visual Studio and so, from the File menu, cull the Open Web Site option, scan to the BookReviewsWSP
folder on your Desktop, and click OK.
The remaining two sections in this tutorial await at what files you lot volition need to copy to the product environment when deploying the awarding. The next two tutorials - Deploying Your Site Using FTP and Deploying Your Site Using Visual Studio - show different ways to copy these files to a web host provider.
Determining the Files to Deploy for the Web Awarding Project
The Web Application Project model uses explicit compilation - the project's source code is compiled into a single assembly each time you build the application. This compilation includes the ASP.Internet pages' code-backside files (~/Default.aspx.cs
, ~/Virtually.aspx.cs
, and so on), as well equally the BasePage.cs
class. The resulting assembly is named BookReviewsWAP.dll and is located in the application's Bin
directory.
Effigy 2 shows the files that make upward the Book Reviews Web Application Project.
Figure two: The Solution Explorer lists the files that incorporate the Web Application Project
To deploy an ASP.NET application adult using the Web Application Project model start by building the application so as to explicitly compile the most recent source code into an assembly. Adjacent, re-create the post-obit files to the production environment:
- The files that contain the declarative markup for every ASP.NET folio, such every bit ~/
Default.aspx
, ~/Most.aspx
, and so on. Also, re-create upwardly the declarative markup for any master pages and User Controls. - The assemblies (
.dll
files) in theBin
folder. Y'all practise not demand to re-create the programme database files (.pdb
) or whatever XML files you may find in theBin
directory.
Yous practise not need to copy the ASP.Net pages' source code files to the production environment, nor do y'all need to copy the BasePage.cs
grade file.
Annotation
As Figure ii shows, the BasePage
class is implemented as a class file in the project, placed in folder named HelperClasses
. When the project is compiled the lawmaking in the BasePage.cs
file is compiled forth with the ASP.Net pages' code-behind classes into the single assembly, BookReviewsWAP.dll.
ASP.NET has a special folder named App_Code
that is designed to hold class files for Spider web Site Projects. The lawmaking in the App_Code
binder is automatically compiled and therefore should not be used with Web Application Projects. Instead, yous should identify your application's class files in a normal folder named HelperClasses
, or Classes
, or something similar. Alternatively, you can place class files in a separate Class Library projection.
In addition to copying the ASP.NET-related markup files and the assembly in the Bin
folder, you likewise demand to re-create the client-side support files - the images and CSS files - equally well every bit the other server-side support files, Spider web.config
and Spider web.sitemap
. These client- and server-side support files demand to be copied to the product environment regardless of whether you use explicit or automated compilation.
Determining the Files to Deploy for the Spider web Site Project Files
The Spider web Site Projection model supports automatic compilation, a feature not available when using the Web Application Project model. With explicit compilation you must compile your project's source lawmaking into an assembly and copy that assembly to the production surround. On the other hand, with automatic compilation y'all but copy the source lawmaking to the production surround and it is compiled by the runtime on need as needed.
The Build menu choice in Visual Studio is nowadays in both Spider web Awarding Projects and Web Site Projects. Building a Spider web Application Projects compiles the projection'south source code into a single assembly located in the Bin
directory; edifice a Web Site Projection checks for any compile-time errors, just does non create whatever assemblies. To deploy an ASP.Cyberspace application developed using the Web Site Projection model all you lot demand to do is copy the appropriate files to the production environment, simply I would encourage you to first build the project to ensure that there are no compile-time errors.
Figure three shows the files that make up the Volume Reviews Web Site Project.
Figure iii: The Solution Explorer lists the files that comprise the Web Site Project
Deploying a Web Site Projection involves copying all of the ASP.Net-related files to the production surroundings - that includes the markup pages for ASP.Internet pages, master pages, and User Controls, along with their lawmaking files. Y'all also need to copy up any class files, such as BasePage.cs. Note that the BasePage.cs
file is located in the App_Code
folder, which is a special ASP.Cyberspace folder used in Web Site Projects for class files. The special folder needs to exist created on production, besides, every bit the course files in the App_Code
folder on the development environment must be copied to the App_Code
folder on production.
In improver to copying the ASP.NET markup and source code files, you besides need to re-create the customer-side support files - the images and CSS files - as well every bit the other server-side support files, Web.config
and Web.sitemap
.
Note
Web Site Projects tin too apply explicit compilation. A future tutorial volition examine how to explicitly compile a Web Site Project.
Summary
Deploying an ASP.Internet application entails copying the necessary files from the evolution surround to the production environment. The precise set up of files that need to be synced depends on whether the ASP.Internet awarding'due south lawmaking is explicitly or automatically compiled. The compilation strategy employed is influenced by whether Visual Studio is configured to manage the ASP.NET application using the Web Application Project model or the Web Site Project model.
The Web Awarding Project model uses explicit compilation and compiles the projection's code into a single assembly in the Bin
binder. When deploying the application, the markup portion of the ASP.Net pages and the contents of the Bin
binder must be pushed up to the product environment; the source code in the application - the lawmaking files and code-backside classes, for example - practise non need to be copied to the production environment.
The Web Site Project model uses automated compilation by default, although it is possible to explicitly compile a Spider web Site Project, equally nosotros will see in future tutorials. Deploying an ASP.Internet application that uses automatic compilation requires that the markup portion and source code must exist copied to the production environment. The code is automatically compiled on the production environment when it is requested for the start time.
Now that we have examined what files need to be synced betwixt the development and product environments we are ready to deploy the Volume Reviews application to a web host provider.
Happy Programming!
Farther Reading
For more information on the topics discussed in this tutorial, refer to the following resource:
- ASP.NET Compilation Overview
- ASP.NET User Controls
- Examining ASP.NET'southward Site Navigation
- Introduction to Web Awarding Projects
- Primary Page Tutorials
- Sharing Code Between Pages
- Using a Custom Base of operations Grade For Your ASP.Cyberspace Pages' Code-Behind Classes
- Visual Studio 2005's Web Site Projection System: What Is Information technology and Why Did Nosotros Do It?
- Walkthrough: Converting a Web Site Project to a Web Application Project in Visual Studio
Source: https://docs.microsoft.com/en-us/aspnet/web-forms/overview/older-versions-getting-started/deploying-web-site-projects/determining-what-files-need-to-be-deployed-cs
0 Response to "Visual Studio Also Upload Code Behind Files"
Post a Comment