I am currently converting a lot of legacy ASP.NET website over to ASP.NET Web Application Projects. The reason for doing this is so I can make my NUnit Test project reference my Web Application Project. There are various discussions about ASP.NET: Web Site vs. Web Application, but for me it was solely for testability purposes.
In Visual Studio 2008, the process to convert a Web site over to a Web Application project is relatively painless:
- Create a Web Application project, File -> New -> Project, then select “ASP.NET Web Application”.
- Once the project is created, delete all files apart from the project itself.
- In Visual Studio ensure both the Web Site and Web Application projects are open.
- Using Visual Studio select all the files from your Web Site and copy them to your Web Application project.
- Then select your Web Site, right click -> Property Pages and select references. Make a note of all the references.
- Select your Web Application project and add all the references you made a note of in the previous step.
- Finally select your Web Application project, right click and select Convert to Web Application.
- Optional rename the Old_App_Code folder to anything but App_Code, I usually rename it Infrastructure.
You should now be able to build your application as usual. The only problem I’ve found so far is; if you have been loose with your namespaces in the App_Code folder, you will need ensure you use namespaces as you would normally, then add the using directive in the normal way to your pages. The reason for this is in a Web Site anything in the App_Code folder is automatically available to all ASP.NET pages, regardless of the namespace!
Update: I ran into one other issue when using ASP.NET Profile in Web Application Projects, unfortunately when using a Web Application Project the proxy class that is created automatically to wire up your custom fields doesn’t get created (as it does when using App_Code in a Web Site). The proxy class is used to access strongly-typed properties; representing the Profile fields you defined in your web.config.
Luckily Joe Wrobel has a excellent solution for this problem, thanks Joe!Don’t forget to add WebProfile.cs to your project (the MSBuild task creates this for you, in the root folder of your project).