Click here to go directly to the instructions…

Background (Click above to skip if you know Web Application Projects)

In VS 2002/2003, the web project model for a website was similar to “class library” projects, where you have a .CSPROJ or .VBPROJ file that keeps track of files “included” in the project, and compiles all the pages and controls code behind to a single assembly under “bin”. Each page/control has an automatically generated .DESIGNER.CS or .DESIGNER.VB file, which contains objects mapping to the server controls in the page/control markup (the generation of those files was not always in synch with markup, and that was problematic).

With VS 2005, there was a new “website” model for web projects that compiles each page/control individually as a separate assembly (or each folder, depending on optimization features), and applies this to all files in a given directory and its sub folders. This was a total mess in most “real world” projects, as VS takes so long to build the entire website, and even at deployment, you get sometimes many problems when you have pages that “reference” other pages/controls when IIS it trying to dynamically load the right assemblies to reference, and many other problems.

So, Microsoft came with a new add in to VS 2005 called “Web Application Projects“. This is typically the same old VS 2002/2003 project model with no problems in generating DESIGNER files and with integration with both IIS and ASP.NET development server that comes embedded in VS 2005/2008. It was later merged with VS 2005 SP1, and shipped as part of VS 2008 (without removing the “website” model). Note that most stuff that has to do with Microsoft like ASP.NET AJAX Toolkit Sample website and so are actually “web applications” not “websites”.

The problem

Typically, when you are converting any project from VS 2003 to VS 2005 SP1, it converts as “web application” not “website”. You can also convert a “website” to a “web application”. There’s an option “Convert to web application” to look for.

In my company, all our web projects are “web applications”, well, except that other web project I was code reviewing and helping with its deployment! After spending number of days with the brilliant team and not finding as many items to code review and getting sick of some problems at sometime in deployment, I cried to them to convert it to to “web application” (maybe I was looking for some job to be doing :D). Very confidently, I said, ” remember the option exists and I did conversion before in VS 2005. All it takes is a right click on the ‘website’ root node in solution explorer in VS 2008 and ‘Convert to web application’. It almost never causes any problems, and we have our source control anyway”.

They believed they had time to do it, so, they went to look for that menu item  “Convert to web application” and guess what ? They didn’t find it! They tried resetting VS 2008 settings and everything, and still, nothing there!!! Yeah, it was embarrassing :D :D :D

Workaround, or, how to convert a “website” to “web application” in VS 2008

Well, it turns out that the option “Convert to web application” does NOT exist for “websites”. The option “Convert to web application” does exist only for “web applications” !!!!

So, here’s the deal, to do the conversion, you need to:

  • Add a new “Web Application” to your VS 2008 solution (File->Add->New Project->C#->Web->ASP.NET Web Application).
  • Afterwards, you copy all the files in the old “website” to your newly created “web application”, and override any files created in it by default
  • The next step is the most ugly, you need to “manually” add the references in your “website” to the new “web application”. I thought the VS 2008 PowerCommands toy would do this for me as it does copy references from other project types, but it didn’t. You have to do it by yourself, manually, and you have to be cautious in this step if you have multiple versions of the same assembly (like AJAXToolkit in my case) or assemblies that have both GAC and local versions or so.
  • Keep repeating the last step and trying to build the “web application”. You’ll keep getting errors like ” ‘….’ is unknown namespace. Are you missing an assembly reference? “. Make sure you have none of those except the ones where ‘….’ is replaced by the IDs of the server controls you use. In other words, keep adding references and building the project until only the errors that exist because of missing .DESIGNER.CS or .DESIGNER.VB files.
  • Afterwards, go to the “web application” root project node in VS 2008 solution explorer, and right click it, then you WILL find the option “Convert to web application”. What this option does is actually making small changes to the “@Page” and “@Control” directives of pages and controls, and creating the required .DESIGNER.CS or .DESIGNER.VB files.
  • Try building the “web application” again. If you get errors, see what references may be missing and/or go click the “Convert to web application” again. Sometimes, if there’s any error other than those caused of missing DESIGNER files, not all the pages/controls will have those DESIGNER files created for them. Fixing the non DESIGNER problem and clicking “Convert to web application” again should do the job for this.
  • Once you are done successful VS build, you should be ready to go. Start testing your web application. Optionally, you can right click the “web application” root project node in VS 2008 Solution Explorer and click “Properties” then go to the tab “Web” to set the “web application” to a virtual folder in IIS (you can create new virtual directory from there in VS). If you want to use the IIS virtual directory that the old “website” used, you need to remove that from IIS first.
  • Update: When testing your pages, pay MOST ATTENTION to classes in “App_Code” folder, especially those with NO NAMESPACE. Those can be a big trap. We had a problem with two extension method overloads in the same static class that had no namespace,one extends DateTime? (Nullable<DateTime>) and calls another overload that extends DateTime itself. Calling the other overload as extension method passed VS 2008 compilation and gave us a compilation error ONLY IN RUNTIME (With IIS). Changing the call to the other overload from calling it as extension method to calling it as normal static method (only changing the call in the same class, calls from other classes remained extension method calls) did solve this one, but clearly, it’s not as safe as it used to be in VS 2005. Especially with classes with no namespaces.
  • Update2: During the conversion, VS 2008 renames your “App_Code” to “Old_App_Code”. This new name sounds ugly, but DO NOT RENAME IT BACK. In the “web application” model, all code will be in one assembly. In runtime, the web server does not know what web project type you are using. It does take all code in “App_Code” folder and create a new assembly for it. This way, if you have code in folder named “App_Code”, you’ll end up with RUNTIME compilation errors that the same types exist in two assemblies, the one created by VS, and the one created by IIS / ASP.NET Development Server. To avoid that. leave the “Old_App_Code” with the same name, or rename it to ANYTHING EXCEPT: “App_Code”. Do not place any code in such “App_Code” folder and prefereably do NOT have a folder with such name in your “web application” at all.
    I know this since before but forgot it now as I have not used “website” model for long :(.

I hope this helps anyone to avoid my embarrassment, and still get rid of the weird errors of “website” model :).

Now that we're done, click this out ;)

, , , , ,
  • http://mnour.blogspot.com Mohammed Nour El-Din

    Nice Hint :)

  • http://

    Now I’m converting a VS 2003 web application into VS 2008, I think I don’t need to perform “Convert to web application”, right?
    I tried to do “Convert to web application”, then many additional *.designer.cs were generated. I’m not sure what this convertion for ? Should i do it or not?
    Please advice, thanks a lot.

  • http://weblogs.asp.net/meligy Mohamed Meligy

    When you migrate VS 2003 web project to VS 2005 with SP1 installed or VS 2008, the migration used the web application model not the website model by default.
    The additional .designer.cs files are just normal. This is the replacement in VS 2005 and later to the “Designer Generated Code” C# region that VS 2003 places in .cs files for the use of VS designer.
    You should be OK by just opening the .csproj or .sln file inside VS 2008.

  • http://

    Thanks, a very useful article, I faced most of the mentioned points and this article helped me a lot.

  • http://blog.benhartonline.com benhart

    I’ve just faced the same problem! I’m too a little red faced after repeatedly saying “just right click the site, and select “Convert to Web Application”! Doh, that item no longer exists. What a joke!

    Thanks for your steps, I appreciate having them as a guide. I’m still a little bitter that I have to follow them in the first place, though :)

  • http://

    !!!! BEWARE !!! – This does not work for web sites that have nested user controls. The convert to web application is not recursive and cannot create the designer files appropriately. It only appears to go one level deep when converting user controls which causes errors.

  • http://

    Thanks

  • http://

    When converting to a Web Application, after the conversion process has created your designer.cs file, be sure that the class definition within that file is correct.

    In my case, as an example, I had one aspx file, Default.aspx, with Default.aspx.cs associated to it. The class definition within Default.aspx.cs was:

    public partial class _Default : System.Web.UI.Page {…}

    Default.aspx was inheriting the “_Default” class. Fine, great. That’s expected. That’s how it was in my Web Site project and it worked fine.

    After some build failure frustration, I discovered that Default.aspx.designer.cs was auto-generated using the following class definition:

    public partial class Default {…}

    All the controls were there. They were all named correctly. The problem was that Visual Studio, for whatever reason, did not want to use “_Default”, but instead, “Default” in the designer class file’s class definition.

    Hopefully that will help someone avoid the frustration I experienced from this small oversight.

  • http://inayathullah@cba.edu.sa Inayathullah

    Hello Sir,

    My self Website developer, Our website was developed in VS2003, now I want to convert into VS2008, so how to convert all .aspx.vb pages and .ascx and .xsd files, I want to change aspx.vb to aspx.cs plz send me a procedure… step by step how to solve this problem…

    Hope that you will send me needfull reply.
    Thanking you sir,

    Best Regards
    inayath

  • http://www.thehazymind.com Michael Schuld

    Thanks for that. I had a TON of “errors” in ReSharper that have now disappeared as it knows how to find all of my controls.

  • http://

    I have converted my old VS2008 Website to Web Application, now everything was working before I tried to convert it. But now I don’t seem to be able to reference my Classes? For example I have a BasePage class that every .aspx page inherits like so

    public partial class SomePageName : BasePage
    {
    }

    But now I get this message? And the same for all the other classes?

    The type or namespace name ‘BasePage’ could not be found (are you missing a using directive or an assembly reference?)

    How do I find out which ‘using’ directive I am missing and whats an assembly reference?

  • http://weblogs.asp.net/meligy Mohamed Meligy

    Where is the PageBase class defined? In the website/application or in a referenced library?
    If it was inside the website app_code folder before conversion, where is it located in the new web application?

    Also, is the PageBase class included in a namespace? IF not try to put it in a namespace.

  • http://

    i am trying to Convert VS2008 web site project to Web Application Project. i gone through documentation of this topic.

    Created a new web application project and copied all files and folders from web site project to newly created Web Application Project. we need to add References manually. i right click project node —> Add references —-> Browse here i can browse only .dll, .exe, manifest and some more files. but in our project we have .aspx files and some other files.

    so i am not able to add references for .aspx files and etc.

  • http://weblogs.asp.net/meligy Mohamed Meligy

    You do not need to “Add reference” but to include the files.

    In Solution Explorer tool window, there are some icons just under the window title. Look for the icon to the left to the “Refresh” icon, it reads “Show All Files” when you hover it.
    Click this icon and you’ll see the files you pasted. Select those files, right click them, and from the right click menu choose “Include in project”, then go to the web application Project node again in Solution Explorer, right click, and choose “Convert to Web Application” as the above steps say.

    If you have trouble with showing those files, it may be easier to delete the files you copied, copy the original files again, but do NOT paste the file in the web application folder in Windows Explorer, instead do this: go to Visual Studio, right click the Web Application Project node in Solution Explorer, you’ll find in the right click menu an option “Paste”. Use this to paste your files, and continue with the steps normally.

  • http://

    I’ve done all these steps and still, none of my .aspx can reference my user or custom controls. And none of my .ascx can reference my custom controls. I’ve tried everything.

  • http://weblogs.asp.net/meligy Mohamed Meligy

    From what you are describing, it seems like “Convert to Web Application” step is not having effect for you. This can happen if you have build errors.
    Please open the original website in its original VS Solution and confirm that the entire solution compiles correctly, then, go to the web application (maybe better create yet another new Web Application), go add reference to ALL the libraries that original website had reference to (or were in its ‘bin’ folder). Make sure all references are there.
    Now, cop the files from original website and paste them in the new Web Application (using VS for Paste, not Windows Explorer).
    Then try “Convert to Web Application” on the newly created web application two or three times and build the web application after every time. See if the build errors are less after every time. Also, search in the build errors for any other errors than those generated because the pages and controls are not seeing each other.
    Check if there are “.aspx.designer.cs”, “.ascx.designer.cs” OR “.aspx.designer.vb”, “.ascx.designer.vb” were generated for your web application after “Convert…” or no.

    If you still have problems, send me a screenshot of your new Web Application in VS if possible, or at least, copy the complete list of errors and warnings you are getting on build.

  • http://

    Excellent Article

    For those using a custom ASP.NET Profile class, they may have an Update3 as well. To resolve any Profile build errors when converting from a WebSite to a Web Application, they may reference the following article:

    http://weblogs.asp.net/jgalloway/archive/2008/01/19/writing-a-custom-asp-net-profile-class.aspx

  • http://

    So I followed these instructions. Every time I open the application after that it immediately converts it to a website and I need to start the process all over again. any suggestions?

  • http://weblogs.asp.net/meligy Mohamed Meligy

    You cannot easily convert a web application back to website as per my understanding.

    Are you sure you are openning the new project you created not the old website?

  • http://vnmxniukjsxy.com/ jjemzaf

    IS5dym rlvymdqrbzjv, [url=http://gapsdsznbclc.com/]gapsdsznbclc[/url], [link=http://gqsubetggmdu.com/]gqsubetggmdu[/link], http://hjehoszcboaj.com/

  • Tilton

    Excellent Article.
    Thanks a lot.

  • Mark Kamoski

    I did not have the “Convert to web application” option anywhere to be found. Furthermore, this flat-out did not work for me. I had a web site project with one ASPX and one ASCX in it. I moved the code. I move the references. It would not compile. It could not find the controls on the code-infront and wire them to the code-behind. Oh well.

  • Kamlesh

    It is a nice artical, i did everyting mentioned in the artical but facing following two issues in the newly created web application

    1. global.asax is generated as a script file having inline code and is not able to access one of the classes defined under old_app_code folder. The name ‘classname’ does not exist in the current context, is the error that I am getting. This class is accessed in Application_End function, not sure why application is going to this function at the start itself.
    2. My old website was having webreference for two webservices, when i copy these files to web application all files are displayed as individual files disco, discompa, wsdl are not linked as single file. Application gives compile time error as it is not able to get reference of these webservices.

    What should I try to fix these errors.

    Thanks a lot.

  • Johann V Gunnarsson

    I successfully converted a VS.2003 website to an VS.2008 Web Application:

    #1 Created another “web application” project within the same solution.
    #2 Copied all files from the website into the Web Application project. (Did the copying within the VS2008 environment)
    #3 Selected all files within the “Web application”, right clicked the selection and selected “Convert to Web Application”.
    #4 Deleted the Website from the solution.

    …of course I had some minor issues to clean up afterwards, but all related to the project structure and dependencies. The conversion was successful.

    Thx.

  • noeldp

    I ran across this after many hours trying to figure out what happened to class references after upgrading VS2003 to VS2008. This is great documentation but a heck of a lot of extra work. The real problem is that MS failed to follow a general enhancement principle: “Always Give Folks Everything They Had Before, And More”, by taking away ‘Convert to Web Application’. Furthermore a web project of ANY type should be able to have web pages inherit a base class within the project without jumping through hoops. MS – please put these fixes in VS2010 (or beyond). Thanks!

  • noeldp

    Possible solution (worked for me :)
    1. Open VS2003 web solution in VS2005 and convert
    (ignore any errors)
    2. Right-click solution and Convert to Web Application
    (ignore any errors)
    3. Open VS2005 web application in VS2008 and convert
    (fix any errors, and optionally fix warnings)

    This successfully carried forward an inherited VS2003 basepage to VS2008 with zero errors and a few warnings. It remained a Web Application, not a Web Site. Much easier starting point for further updates.

  • Nimesh

    HI…
    I have added

    in the page. when i click Convert to web application, its giving an error like:

    Generation of designer file failed: Unknown server tag ‘cc1:Rating’

    What could be the solution for this?

  • Richard

    Thanks. Followed your directions, it worked perfectly. I didn’t have even build errors.

  • monts

    thanks. you saved me hours

  • http://neworleanssaintsmerchandise.net/ New Orleans Saints Merchandise

    This is actually one of many much better reports associated with those who We have read more this particular matter nowadays. Fantastic function.

  • Pingback: Converting a vs 2010 website to a web application « Dead Code

  • http://www.myfoldingshoppingcart.com Folding Shopping Carts

    Thing you are talking about a lot of. Nonetheless, picture this, suppose you integrated more of stuff? What i’m saying is, I don’t tend to tell you how you can write your blog, but if you added something which can get peoples particular attention? Simply like a video or simply a image or perhaps few to get viewers psyched about what you are talking about.

  • http://hotrendytopics.info/ Leone Gareau

    Is definitely blogengine greater than wordpress in some manner? Must be since it is increasingly popluar of late.

  • http://celeberitygossipvi.info/bookmarks/ Twanna Mcguinness

    Whoa! Photograph hunting yahoo and google all day due to this and i also as a final point thought it was here!

  • http://workbusinessjobs.blogspot.com/ Vickey Hambelton

    Thanks for your post. After reading through your post, I was able to get some bloging ideas from your information you provided. I hope you don’t mind if I use it on my blog. I’ve bookmarked your site. Thanks.

  • http://www.asdfbas.com Joe

    Hey, very nice blog post!

  • http://buyresveratrolonline.org/resveratrol-capsules-are-resveratrol-capsules-worth-it-or-not/ resveratrol capsules

    Could you write another article about this topic due to the fact that this post was a bit hard to comprehend?

  • http://devvicky.com/ free microsoft word

    very informative post. Looking more to something like this

  • http://methehottesttopics.info/ Stuart Aybar

    Terrific article, well written I must say.

  • http://irsportsnews.info/ Jeane Bruchey

    Is definitely blogengine superior to wp somewhat? Must be as it would be starting to be popluar as of late.

  • http://www.londonpizzadelivery.com pizza delivery in london

    I was reading something else about this on another blog. Interesting. Your position on it is diametrically contradicted to what I read in the first place. I am still pondering over the different points of view, but I’m inclined heavily toward yours. And irrespective, that’s what is so good about modern-day democracy and the marketplace of thoughts on-line.

  • http://www.londonpizzadelivery.com london pizzas

    This is the incident that we are scanning anything about developing blogs with the system. It looks that you are an extremely expert blogger. Your method is an superb example of why I keep coming back to study your excellent quality content that is forever updated.

  • http://www.articlecounty.com/index.php?page=article&article_id=749190 Roger Murray

    Greet post this will really help me.

  • http://www.vacant.org.uk/jrforum/viewtopic.php?f=2&t=10827&p=195813#p195813 Denver Adhami

    I do not think I have ever witnessed your web site with this many comments into it!

  • http://kassarctest.com Alvera Wyrostek

    Most of the times i visit a blog i get disappointed. Regarding your blog,I could honestly say that you writting is decent and your website solid.

  • http://wowcatalevelguide.yolasite.com/ Keri Wetmore

    I the efforts you have put in this, regards for all the great posts .

  • http://chrisma79.kafechew.info/uncategorized/promotional-usb-sticks/ Latrina Guerette

    Lastly, an issue that I am enthusiastic about. I’ve seemed for info of this caliber for the last a number of hours. Your website is significantly appreciated.

  • http://www.squidoo.com/celtic-tattoos-for-girls celtic tattoos

    Thank you for this fantastic topic and narrative of this question. You’ve turned it out better than any talks I’ve seen. Also thank you for citing my classwork on it. Your’s takes it higher.

  • http://www.squidoo.com/religious-tattoos-for-girls religious tattoos for girls

    Thanks for writing about this. There’s a bunch of good tech info on the internet. You’ve got a lot of that info here on your web site. I’m impressed – I try to keep a couple blogs reasonably up-to-date, but it’s a struggle sometimes. You’ve done a solid job with this one. How do you do it?

  • Jesper Mygind

    Very helpful. Worked in VS2010. Regarding files in App_Code with no namespace: Before the conversion I created a new class library project, copied the files from App_Code to the new project, built it and referenced it from my web project. Saved a lot of trouble.