{"id":157,"date":"2010-04-17T21:11:52","date_gmt":"2010-04-17T21:11:52","guid":{"rendered":"http:\/\/blog.rabihtawil.com\/?p=157"},"modified":"2023-01-13T22:38:39","modified_gmt":"2023-01-13T22:38:39","slug":"using-c-and-vb-in-the-same-web-project","status":"publish","type":"post","link":"http:\/\/www.raytawil.com\/?p=157","title":{"rendered":"using c# and vb in the same web project"},"content":{"rendered":"<p>Can you have both c# and visual basic in the same web site project?<\/p>\n<p>Definitely! It simply wouldn&#8217;t make sense from a new project standpoint, code reviews, coding standards, continuity, project maintenance, etc.<\/p>\n<p>however, people still want it.\u00a0 to-date i never really tried (and that&#8217;s been my answer).\u00a0 I was presented with a usable scenario of why you may need (not want, need) to do this, so I finally tried it.\u00a0 the answer: yes&#8230;kinda&#8230;sometimes.<\/p>\n<p>let&#8217;s assume we have a web site structure like this:<\/p>\n<p>we have the App_Code folder and a .cs and a .vb file in the same projects (separated into sub-folders).\u00a0 note that the project sees them as folders (yellow folder icon) in the special folder.\u00a0 each class within there basically has a &#8220;hello world&#8221; function only, like this in the c# file:<\/p>\n<pre><\/pre>\n<div id=\"wpshdo_1\" class=\"wp-synhighlighter-outer\"><div id=\"wpshdt_1\" class=\"wp-synhighlighter-expanded\"><table border=\"0\" width=\"100%\"><tr><td align=\"left\" width=\"80%\"><a name=\"#codesyntax_1\"><\/a><a id=\"wpshat_1\" class=\"wp-synhighlighter-title\" href=\"#codesyntax_1\"  onClick=\"javascript:wpsh_toggleBlock(1)\" title=\"Click to show\/hide code block\">Source code<\/a><\/td><td align=\"right\"><a href=\"#codesyntax_1\" onClick=\"javascript:wpsh_code(1)\" title=\"Show code only\"><img border=\"0\" style=\"border: 0 none\" src=\"http:\/\/www.raytawil.com\/wp-content\/plugins\/wp-synhighlight\/themes\/default\/images\/code.png\" \/><\/a>&nbsp;<a href=\"#codesyntax_1\" onClick=\"javascript:wpsh_print(1)\" title=\"Print code\"><img border=\"0\" style=\"border: 0 none\" src=\"http:\/\/www.raytawil.com\/wp-content\/plugins\/wp-synhighlight\/themes\/default\/images\/printer.png\" \/><\/a>&nbsp;<a href=\"http:\/\/www.raytawil.com\/wp-content\/plugins\/wp-synhighlight\/About.html\" target=\"_blank\" title=\"Show plugin information\"><img border=\"0\" style=\"border: 0 none\" src=\"http:\/\/www.raytawil.com\/wp-content\/plugins\/wp-synhighlight\/themes\/default\/images\/info.gif\" \/><\/a>&nbsp;<\/td><\/tr><\/table><\/div><div id=\"wpshdi_1\" class=\"wp-synhighlighter-inner\" style=\"display: block;\"><pre class=\"csharp\" style=\"font-family:monospace;\"><span class=\"kw1\">public<\/span> <span class=\"kw4\">string<\/span> SayHelloCS<span class=\"br0\">&#40;<\/span><span class=\"br0\">&#41;<\/span>\n    <span class=\"br0\">&#123;<\/span>\n      <span class=\"kw1\">return<\/span> <span class=\"st0\">&quot;Hello from CS&quot;<\/span><span class=\"sy0\">;<\/span>\n  <span class=\"br0\">&#125;<\/span><\/pre><\/div><\/div>\n<pre>and the visual basic file has a similar function emitting \"Hello from VB.\"<\/pre>\n<p>now, if you run default.aspx in this structure, this is what you will see:<\/p>\n<p><em>The files &#8216;\/WebSite5\/App_Code\/VBCode\/Class2.vb&#8217; and &#8216;\/WebSite5\/App_Code\/CSCode\/Class1.cs&#8217; use a different language, which is not allowed since they need to be compiled together.<\/em><\/p>\n<p>interesting?\u00a0 probably not, but it makes sense&#8230;so how do we overcome.\u00a0 we use a configuration option called <a onclick=\"javascript:pageTracker._trackPageview('\/outgoing\/msdn2.microsoft.com\/en-us\/library\/54dwfbb7.aspx');\"  href=\"http:\/\/msdn2.microsoft.com\/en-us\/library\/54dwfbb7.aspx\" rel=\"tag\">codeSubDirectories<\/a>.\u00a0 here&#8217;s what we need to add to our &lt;compilation&gt; node in our web.config:<\/p>\n<pre><\/pre>\n<div id=\"wpshdo_2\" class=\"wp-synhighlighter-outer\"><div id=\"wpshdt_2\" class=\"wp-synhighlighter-expanded\"><table border=\"0\" width=\"100%\"><tr><td align=\"left\" width=\"80%\"><a name=\"#codesyntax_2\"><\/a><a id=\"wpshat_2\" class=\"wp-synhighlighter-title\" href=\"#codesyntax_2\"  onClick=\"javascript:wpsh_toggleBlock(2)\" title=\"Click to show\/hide code block\">Source code<\/a><\/td><td align=\"right\"><a href=\"#codesyntax_2\" onClick=\"javascript:wpsh_code(2)\" title=\"Show code only\"><img border=\"0\" style=\"border: 0 none\" src=\"http:\/\/www.raytawil.com\/wp-content\/plugins\/wp-synhighlight\/themes\/default\/images\/code.png\" \/><\/a>&nbsp;<a href=\"#codesyntax_2\" onClick=\"javascript:wpsh_print(2)\" title=\"Print code\"><img border=\"0\" style=\"border: 0 none\" src=\"http:\/\/www.raytawil.com\/wp-content\/plugins\/wp-synhighlight\/themes\/default\/images\/printer.png\" \/><\/a>&nbsp;<a href=\"http:\/\/www.raytawil.com\/wp-content\/plugins\/wp-synhighlight\/About.html\" target=\"_blank\" title=\"Show plugin information\"><img border=\"0\" style=\"border: 0 none\" src=\"http:\/\/www.raytawil.com\/wp-content\/plugins\/wp-synhighlight\/themes\/default\/images\/info.gif\" \/><\/a>&nbsp;<\/td><\/tr><\/table><\/div><div id=\"wpshdi_2\" class=\"wp-synhighlighter-inner\" style=\"display: block;\"><pre class=\"asp\" style=\"font-family:monospace;\"><span class=\"sy0\">&lt;<\/span>compilation debug<span class=\"sy0\">=<\/span><span class=\"st0\">&quot;false&quot;<\/span><span class=\"sy0\">&gt;<\/span>\n          <span class=\"sy0\">&lt;<\/span>codeSubDirectories<span class=\"sy0\">&gt;<\/span>\n            <span class=\"sy0\">&lt;<\/span>add directoryName<span class=\"sy0\">=<\/span><span class=\"st0\">&quot;VBCode&quot;<\/span><span class=\"sy0\">\/&gt;<\/span>\n            <span class=\"sy0\">&lt;<\/span>add directoryName<span class=\"sy0\">=<\/span><span class=\"st0\">&quot;CSCode&quot;<\/span><span class=\"sy0\">\/&gt;<\/span>\n          <span class=\"sy0\">&lt;\/<\/span>codeSubDirectories<span class=\"sy0\">&gt;<\/span>\n       <span class=\"sy0\">&lt;\/<\/span>compilation<span class=\"sy0\">&gt;<\/span><\/pre><\/div><\/div>\n<p>once we add those codeSubDirectory nodes, let&#8217;s &#8220;look&#8221; at what the project structure looks like now:<\/p>\n<p>as you can see the code folders are now &#8220;special&#8221; in the eyes of visual studio.\u00a0 now if we browse default.aspx we will see:<\/p>\n<div id=\"wpshdo_3\" class=\"wp-synhighlighter-outer\"><div id=\"wpshdt_3\" class=\"wp-synhighlighter-expanded\"><table border=\"0\" width=\"100%\"><tr><td align=\"left\" width=\"80%\"><a name=\"#codesyntax_3\"><\/a><a id=\"wpshat_3\" class=\"wp-synhighlighter-title\" href=\"#codesyntax_3\"  onClick=\"javascript:wpsh_toggleBlock(3)\" title=\"Click to show\/hide code block\">Source code<\/a><\/td><td align=\"right\"><a href=\"#codesyntax_3\" onClick=\"javascript:wpsh_code(3)\" title=\"Show code only\"><img border=\"0\" style=\"border: 0 none\" src=\"http:\/\/www.raytawil.com\/wp-content\/plugins\/wp-synhighlight\/themes\/default\/images\/code.png\" \/><\/a>&nbsp;<a href=\"#codesyntax_3\" onClick=\"javascript:wpsh_print(3)\" title=\"Print code\"><img border=\"0\" style=\"border: 0 none\" src=\"http:\/\/www.raytawil.com\/wp-content\/plugins\/wp-synhighlight\/themes\/default\/images\/printer.png\" \/><\/a>&nbsp;<a href=\"http:\/\/www.raytawil.com\/wp-content\/plugins\/wp-synhighlight\/About.html\" target=\"_blank\" title=\"Show plugin information\"><img border=\"0\" style=\"border: 0 none\" src=\"http:\/\/www.raytawil.com\/wp-content\/plugins\/wp-synhighlight\/themes\/default\/images\/info.gif\" \/><\/a>&nbsp;<\/td><\/tr><\/table><\/div><div id=\"wpshdi_3\" class=\"wp-synhighlighter-inner\" style=\"display: block;\"><pre class=\"dos\" style=\"font-family:monospace;\">Hello world from CS. Hello world from VB<\/pre><\/div><\/div>\n<pre><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Can you have both c# and visual basic in the same web site project? Definitely! It simply wouldn&#8217;t make sense from a new project standpoint, code reviews, coding standards, continuity, project maintenance, etc. however, people still want it.\u00a0 to-date i never really tried (and that&#8217;s been my answer).\u00a0 I was presented with a usable scenario [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[110,6],"tags":[128,20,21,26,27,87,88,91,92,94,95,129],"_links":{"self":[{"href":"http:\/\/www.raytawil.com\/index.php?rest_route=\/wp\/v2\/posts\/157"}],"collection":[{"href":"http:\/\/www.raytawil.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.raytawil.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.raytawil.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.raytawil.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=157"}],"version-history":[{"count":2,"href":"http:\/\/www.raytawil.com\/index.php?rest_route=\/wp\/v2\/posts\/157\/revisions"}],"predecessor-version":[{"id":365,"href":"http:\/\/www.raytawil.com\/index.php?rest_route=\/wp\/v2\/posts\/157\/revisions\/365"}],"wp:attachment":[{"href":"http:\/\/www.raytawil.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=157"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.raytawil.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=157"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.raytawil.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=157"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}