Monday, May 7, 2012

Convert ASP.NET Web Site project to Web Application project

Web sites projects use visual studio template of web site project which has certain limitation in terms of managing it e.g. its difficult to maintain web.config file for different environments. Web Application template gives the ability to manage web.config file for different environment using transformation file. In this way, you only need to manage the differences in different environment, and do not copy entire web.config for different environment.
To read more about this go to this link http://msdn.microsoft.com/en-us/library/dd465326.aspx

In order to convert a web site to web application project follow the below steps:
  • Create a new Empty Web Application Project (.NET 4.0) in your solution
  • Add all assembly references and web references to the project. Make sure web references use the same name as in old project.
  • Copy all your files from old web site project to new project directory. Do not copy obj & bin directory and your old web.config files.
  • Include all copied files in your project
  • Right click on your new project and click on Convert to Web Application as shown below:
  • Visual Studio will convert your web site to web application project, after this you will notice that there will be a designer.vb or designer.cs will be created for each asp.net page or user control.
  • Compile your project and resolve any issues you have.
  • Copy the relevant and required section of web.config from your old project to the web.config of your new project. Do not copy paste entire stuff
  • You are done for your local development and testing
  • In the project you will notice two extra config files once you expand web.config file. As shown below, you should see two files by default 1) Web.Debug.config and 2) Web.Release.config. These two files are there to manage configuration differences in different build of the project. E.g. in release build you remove compilation attribute debug=true
  • In order to add new config for your test, production environment. Create a new Build Configuration from Configuration Manager.
  • o Right click on your solution, select Configuration Manager
  • o Select New from Active solution configuration drop down
  • o Type your configuration name e.g. QA and copy the settings from Release Configuration
  • o Once you have added the configuration, right click on web.config file and select Add Config Transforms. This option is only enabled if there is an extra configuration for which transformation can be added. As soon as you click on this it will create the web.QA.config file within web.config.
  • To add transformation rule or change configuration in different environments use transformation syntax. You can use msdn link http://msdn.microsoft.com/en-us/library/dd465326.aspx to learn more about those.
  • Once above step is completed, you can publish your web application (right click on project->publish) and web.config file will have the correct settings based on build configuration you selected from configuration manager.

3 comments:

Macrosoft said...

Got useful information about convert asp.net to web application project.

Convert ASP to ASP.Net

Anonymous said...

I think the content covered in the blog is quite impressive and brilliantly conveyed. Good job and great efforts. Keep it up. ASP.NET Web Application

rmouniak said...

I appreciate your blog
.Net Online Training