Wednesday, November 14, 2007

ASP.NET Web Application Project Upgrade - Assembly Reference not found

We've recently undergone a conversion to Visual Studio 2005 Service Pack 1 (SP1) for the new Web Application Projects (WAP) they have added.

The Web Application Projects give more control over the files included in a Web Site because now you have a project file similar to the VS 2003 Web Application model.

There are a couple of nice guides online to upgrading a Web Site to a Web Application Project after installing SP1, here is one I followed for the Upgrade:
Scott Gu's Migrating a Web Site to Web Application Project.

Basically, you just create a new web application project, copy in all your pages and other files, then on all the ASPX pages, right click and choose "Convert to Web Application", which creates the filename.designer.cs files necessary for the new Web Application Model.

To simplify the upgrade initially I didn't add namespaces for the separate App_Code files and I just put them in a folder named "Classes".

After that there weren't many more hoops to jump through for the site to successfully compile.

One reason for the upgrade is to make it easier to create a Web Setup (Installer) for the Web Application Projects where making a Setup Project for the original "Web Site" project was a pain.

After creating the Web Setup Project for our Web Application Project, then testing the installer, I kept getting an error:
"The name 'Namespace' does not exist in the current context"
When I viewed the detailed compiler output: "The type or namespace name 'Namespace' could not be found (are you missing a using directive or an assembly reference?)". This was because the dll files for the website were not in the bin folder underneath the web application root folder.

Once I fixed this in the installer (I manually added the bin folder available from the "View -> File System" context menu, and added outputs: Primary Output for each web project and library as necessary).

Overall, I'm much happier with the new (or old) Web Application Projects model in Visual Studio 2005, it gives the developer much more control over the behavior of the website, the included files, simplifies deployment, and is much faster to compile and test.

0 comments: