{"id":3364,"date":"2009-10-29T16:49:00","date_gmt":"2009-10-29T16:49:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/webdev\/2009\/10\/29\/converting-a-web-site-project-to-a-web-application-project\/"},"modified":"2009-10-29T16:49:00","modified_gmt":"2009-10-29T16:49:00","slug":"converting-a-web-site-project-to-a-web-application-project","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/dotnet\/converting-a-web-site-project-to-a-web-application-project\/","title":{"rendered":"Converting a Web Site Project to a Web Application Project"},"content":{"rendered":"<p><P>Differences between Web Site Projects (WSP) and Web Application Projects (WAP) are highlighted in blogs <A href=\"http:\/\/vishaljoshi.blogspot.com\/2009\/08\/web-application-project-vs-web-site.html\">such as this one<\/A>. Based on that, if you feel a WAP would be better for your particular needs than a WSP, but have already created a WSP, you may be asking yourself, \u201cCan I convert my WSP into a WAP, without starting from scratch?\u201d.<\/P>\n<P>This posting explains how to convert an existing Web Site Project to a Web Application Project in Visual Studio 2010. The most striking differences to a Web Site Project are that WAPs have a project file to include and exclude files, and compile to a single assembly.<\/P>\n<P>The guidelines below include several of the basic steps detailed in the <A href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/aa983476.aspx\">Walkthrough: Converting a Web Site Project to a Web Application Project in Visual Studio<\/A>. This is an excellent topic to review as it discusses some specific issues you may encounter which were discovered in previous versions of Visual Studio (VS). Please keep in mind while reading it that it is based on a WSP to WAP conversion using previous versions of Visual Studio.<\/P>\n<P>Let\u2019s get started.<\/P>\n<P><STRONG><FONT size=\"2\">Open and Verify your Visual Studio Web Site Project<\/FONT><\/STRONG> <BR>Before converting your WSP to a WAP, you should open it in Visual Studio and verify that is it working correctly.&nbsp; This will help prevent the need to research errors that have nothing to do with the conversion process.<\/P>\n<OL>\n<LI>In the <STRONG>File<\/STRONG> menu, click <STRONG>Open Web Site<\/STRONG>. <\/LI>\n<LI>The <B>Open Web Site<\/B> dialog box is displayed. <\/LI>\n<LI>Select the project folder that you want to open, and then click <B>Open<\/B>. <\/LI>\n<LI>In the <B>Build<\/B> menu, click <B>Build Web Site<\/B>. <\/LI>\n<LI>In the <B>Debug<\/B> menu, click <B>Start Debugging<\/B>. Alternatively, you can press F5. <\/LI>\n<LI>Verify your project compiles and runs as expected <\/LI><\/OL>\n<P><STRONG><FONT size=\"2\">Create a new, empty Visual Studio WAP <BR><\/FONT><\/STRONG>A good strategy for converting a WSP to a WAP is to create a new, blank Visual Studio Web Application Project in a separate directory, but in the same solution. This avoids changing any part of the existing Web site files. It also allows you to copy existing functionality and files into the new WAP easily, within the same Visual Studio instance.<\/P>\n<OL>\n<LI>In the <B>File<\/B> menu, click <B>Add<\/B>, and then click <B>New <\/B><B>Project<\/B>. <\/LI>\n<LI>The <B>Add <\/B><B>New Project<\/B> dialog box is displayed. <\/LI>\n<LI>In the <B>Installed Templates<\/B> section of the <B>Add <\/B><B>New Project<\/B> dialog box, expand the language that you want to use, and then select <B>Web<\/B> to display the Web-related templates. <\/LI>\n<LI>Select <B>Empty <\/B><B>ASP.NET Web Application<\/B>. <\/LI>\n<LI>Type values for <B>Name<\/B>, <B>Location,<\/B> and then click <B>OK<\/B> to create the Web Application Project. <\/LI>\n<LI>After the project has been created, delete the Web.config file that is created automatically. <\/LI><\/OL>\n<BLOCKQUOTE>\n<P><A href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/16\/2019\/02\/WSPandWAP_2.jpg\"><IMG title=\"WSPandWAP\" border=\"0\" alt=\"WSPandWAP\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/16\/2019\/02\/WSPandWAP_thumb.jpg\" width=\"228\" height=\"354\"><\/A> <\/P><\/BLOCKQUOTE>\n<P><STRONG><FONT size=\"2\">Set Project \/ Assembly References<\/FONT><\/STRONG> <BR>If the WSP required additional project or assembly references, you need to add them to the WAP. You can see the list of default references associated with the new (empty) Visual Studio Web Application Project under the References node in Solution Explorer.<\/P>\n<OL>\n<LI>In the <STRONG>Solution Explorer<\/STRONG>, make sure <B>Show All Files<\/B> is turned on. <\/LI>\n<LI>In the <B>Solution Explorer<\/B>, right-click <STRONG>References<\/STRONG>, and then click <STRONG>Add Reference<\/STRONG>. <\/LI>\n<LI>The <STRONG>Add Reference<\/STRONG> dialog box is displayed. <\/LI>\n<LI>Select the reference that you have already added in the Web Site Project and then click OK. <\/LI>\n<LI>Note: To help prevent errors, add references to the Web Application Project for assemblies that existed in the \\bin folder of the WSP. <\/LI><\/OL>\n<BLOCKQUOTE>\n<P><A href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/16\/2019\/02\/AddRef_2.jpg\"><IMG title=\"AddRef\" border=\"0\" alt=\"AddRef\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/16\/2019\/02\/AddRef_thumb.jpg\" width=\"234\" height=\"466\"><\/A>&nbsp;<\/P><\/BLOCKQUOTE>\n<P><STRONG><FONT size=\"2\">Copy and Convert the App_Code folder from the Web Site Project to the Web Application Project<\/FONT><\/STRONG> <BR>In WSPs, the files in the App_Code folder are all compiled together and then referenced (automatically) as a \u201cdll\u201d by all other files in the WSP. In WAPs, this is not the case. All code is compiled together as one .dll. I\u2019ve found that copying the App_Code folder over first and converting it to the WAP model helps to head off some dependency issues which could arise if one copied the entire site, converted, and then tried to compile.<\/P>\n<OL>\n<LI>In the <STRONG>Solution Explorer<\/STRONG>, copy the entire <STRONG>App_Code<\/STRONG> folder from the WSP to the WAP <\/LI>\n<LI>In the <STRONG>Solution Explorer<\/STRONG>, <U>select the WAP\u2019s root node<\/U>; right-click, select <STRONG>Convert to Web Application<\/STRONG> <\/LI>\n<LI>You will see our standard Convert to Web Application confirmation dialog.&nbsp; Select \u201cYes\u201d to this dialog. <\/LI>\n<LI>The <STRONG>App_Code<\/STRONG> folder should now be renamed to <STRONG>Old_App_Code<\/STRONG> folder <\/LI>\n<LI><U>Note:<\/U> Do NOT name it back. As mentioned above, in the WAP model all code will be compiled into one assembly. At runtime, ASP.NET doesn\u2019t know what type of project model you have created and will take anything in the \u201cApp_Code\u201d folder and create a dynamic assembly for it, thereby causing \u201ccould not load type\u201d exceptions as there would be duplicate types exists in two assemblies (the one for the VS web application and the one for App_Code).&nbsp; <A href=\"http:\/\/vishaljoshi.blogspot.com\/2009\/07\/appcode-folder-doesnt-work-with-web.html\">Learn more about why App_Code folder does not work well with WAPs<\/A>. <\/LI>\n<LI>Compile the WAP <\/LI>\n<LI>If you see an error, the most likely causes are: \n<OL>\n<LI>Missing assembly reference. See the section above to add missing references to your project. <\/LI>\n<LI>Files marked with Build Action = Content instead of Build Action = Compile. Any file you want compiled should be marked as such. <\/LI>\n<LI>To set the Build Action property: \n<OL>\n<LI>Select the file in the <STRONG>Solution Explorer<\/STRONG> <\/LI>\n<LI>Press F4 (Brings up the File\u2019s Property Grid) <\/LI>\n<LI>Look at the Build Action property. Change as necessary. <\/LI><\/OL><\/LI><\/OL><\/LI><\/OL>\n<BLOCKQUOTE>\n<P><A href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/16\/2019\/02\/converttowap_2.jpg\"><IMG title=\"converttowap\" border=\"0\" alt=\"converttowap\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/16\/2019\/02\/converttowap_thumb.jpg\" width=\"551\" height=\"428\"><\/A> <\/P><\/BLOCKQUOTE>\n<P><STRONG><FONT size=\"2\">Copy and Convert the remaining Files and Folders from the WSP to the WAP<\/FONT><\/STRONG> <BR>Once your Old_App_Code folder is compiled (by compiling your WAP in the step above), your WAP will have an assembly in the \\bin directory. This will make it easier for the remaining files you are copying over to successfully compile, especially if they reference or use code in the files contained within that folder.<\/P>\n<OL>\n<LI>Select the remaining files \/ folders from the WSP project and copy them into the WAP. <\/LI>\n<LI>Make sure not to copy the <STRONG>App_Code<\/STRONG> folder again. <\/LI>\n<LI>In the <STRONG>Solution Explorer<\/STRONG>, right click the root node of the WAP and select <STRONG>Convert to Web Application<\/STRONG>. \n<OL>\n<LI>Don\u2019t worry, this won\u2019t affect (or try to reconvert) any files or the Old_App_Code folder you have already converted. <\/LI><\/OL><\/LI>\n<LI><U>Note:<\/U> This will cause VS to automatically generate a .designer.cs (or .vb) file for each page, user-control, and master page in the project. Additionally, each .aspx\/.ascx will be modified to use the \u2018Codebehind\u2019 instead of the \u2018CodeFile\u2019 attribute in the Page directive. \n<OL>\n<LI>Example of the \u2018CodeFile\u2019 to \u2018Codebehind\u2019 change \n<OL>\n<LI>WSP file:&nbsp; <FONT face=\"Courier New\">&lt;%@ Page Title=\u201dHome Page\u201d Language=\u201dC#\u201d CodeFile=\u201dDefault.aspx.cs\u201d Inherits=\u201d_Default\u201d %&gt;<\/FONT> <\/LI>\n<LI>Converted WAP file:&nbsp; <FONT face=\"Courier New\">&lt;%@ Page Title=\u201dHome Page\u201d Language=\u201dC#\u201d Inherits=\u201d_Default\u201d Codebehind=\u201dDefault.aspx.cs\u201d %&gt;<\/FONT> <\/LI><\/OL><\/LI><\/OL><\/LI><\/OL>\n<BLOCKQUOTE>\n<P><A href=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/16\/2019\/02\/convertedfiles_2.jpg\"><IMG title=\"convertedfiles\" border=\"0\" alt=\"convertedfiles\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/16\/2019\/02\/convertedfiles_thumb.jpg\" width=\"219\" height=\"469\"><\/A> <\/P><\/BLOCKQUOTE>\n<P><STRONG><FONT size=\"2\">Compile your WAP <BR><\/FONT><\/STRONG>After all the files have been added and converted, you should build your project again to see if there are any compilation errors. At this point, some of the most likely causes of errors are:<\/P>\n<OL>\n<LI>Code files set with Build Action = Content. These should be changed to Compile. Refer to the above section. <\/LI>\n<LI>Missing project or assembly references. See above for steps for adding project or assembly references. <\/LI>\n<LI>Class name collisions. In the WSP model, each .aspx and associated codefile was compiled together as a separate, individual unit. Therefore, one could have files such as foo\\widget.ascx.cs and bar\\widget.ascx.cs where the classes were the same. Once these files are moved to a WAP and all compiled together, class name collisions occur with errors something like, \u201chas multiple definitions with identical signatures\u201d. If this occurs, unique class names should be created. <\/LI><\/OL>\n<P><STRONG><FONT size=\"2\">Run your WAP<\/FONT><\/STRONG> <BR>After completing the above steps and you have a WAP which successfully compiles, you are ready to try running your application. One of the most common problems I\u2019ve seen encountered is the \u201cUnknown server tag \u2018SomeTag: Control\u2019 (as it applies to user controls and such)\u201d. This can be corrected in one of two ways.<\/P>\n<OL>\n<LI>Add or modify the register directive on the page that is using the control. This will only register it for this specific page. \n<OL>\n<LI><FONT face=\"Courier New\">&lt;%@ Register Namespace\u201dnamespace the control is in\u201d TagPrefix=\u201dSomeTag\u201d Assembly=\u201dName of dll compiled into the \\bin folder\u201d %&gt;<\/FONT> <\/LI><\/OL><\/LI>\n<LI>Register the control in the Web.config, making it available to all pages in the project \n<OL>\n<LI>In the &lt;pages&gt;&lt;controls&gt; section add the following: <\/LI>\n<LI><FONT face=\"Courier New\">&lt;add tagPrefix=\u201dSomeTag\u201d namespace=\u201dnamespace the control is in\u201d assembly=\u201d Name of dll compiled into the \\bin folder\u201d \/&gt;<\/FONT> <\/LI><\/OL><\/LI><\/OL>\n<P>Hope this helps!<\/P>\n<P><BR>Nichole Baker <BR>SDET, Visual Studio Web Tools<\/P><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Differences between Web Site Projects (WSP) and Web Application Projects (WAP) are highlighted in blogs such as this one. Based on that, if you feel a WAP would be better for your particular needs than a WSP, but have already created a WSP, you may be asking yourself, \u201cCan I convert my WSP into a [&hellip;]<\/p>\n","protected":false},"author":404,"featured_media":58792,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[197],"tags":[147,7302,7323,7319,7292,7264],"class_list":["post-3364","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-aspnet","tag-visual-studio","tag-visual-studio-2008","tag-visual-studio-2010","tag-visual-web-developer","tag-vs2008","tag-wap"],"acf":[],"blog_post_summary":"<p>Differences between Web Site Projects (WSP) and Web Application Projects (WAP) are highlighted in blogs such as this one. Based on that, if you feel a WAP would be better for your particular needs than a WSP, but have already created a WSP, you may be asking yourself, \u201cCan I convert my WSP into a [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts\/3364","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/users\/404"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/comments?post=3364"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts\/3364\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/media\/58792"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/media?parent=3364"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/categories?post=3364"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/tags?post=3364"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}