Posted By: dotnetjunkie | Mar 20th, 2006 @ 8:34 AM
page 1 of 1
Comments: 23 | Views: 16015
I thought that in VS2005 you could have .cs and .vb files in the same project?

I just tried with an asp.net project and it doesn't work!
It says that the two files use a different language, which is not allowed.
You can mix C# and VB projects in the same solution, but I don't think you can mix them within a project.
sgomez
sgomez
Yada yada yada!
You can't have C# and VB.Net files within the same project.

seb
http://sgomez.blogspot.com
Dan
Dan

You can't have App_Code files with both VB and C#, but you can have one VB ASP.NET page and one C# ASP.NET page in the same project.

Thanks,
-Dan

I think it's because ASPX pages are compiled on the fly, whereas executables and libraries are compiled by their corresponding compilers, csc.exe in C#'s case.

I guess technically someone could write a compiler that puts VB and C# together, but that'd defeat .NET's goal of being language independent, since that compiler would have to accomodate for every language out there.

There's more than 50 .NET languages out there right now, and ASPX supports only two of them.

It's just modularity on a different level, ASPX being arguably more practical but definitely less holistic.
dotnetjunkie wrote:
reinux: I was not talking about executables or libraries but a simple class file or webservice in a web project!

The files in your App_Code directory are compiled on the fly as well, just like the pages, so it must be an architectural limitation!

It seems that everything in App_Code is compiled together in one assembly???!!

Can someone from the team tell a bit more about the exact limitations / architecture and possible solutions?

Ahh sorry, I misread.

Weird... I always thought you could do it.

I can see it being a limitation of CodeDom's architecture though, since CodeDom can spit out assemblies but it can't spit out just raw objects.

There'd be ways to get around it, I'm sure, like ILMerge does, but I guess they figured it wouldn't be worth the trouble Sad
JohnAskew
JohnAskew
9 girl in pink sweater
Maybe compile one as a dll with a nice Interface(s) and use it in the other project through a reference?
Sven Groot
Sven Groot
My name has 9 letters. Coincidence? I think not...
dotnetjunkie wrote:
It seems that everything in App_Code is compiled together in one assembly???!!

That is correct. This assembly is referenced when compiling the pages.

I am having the same type problem, but with a non web project. I would like to not have to rewrite the C# code, but want to use it in my VB.net project.  Any suggestions on if this is possible?

 

Kquad

figuerres
figuerres
???
why not just build a dll and use it??

simple to do, works everytime.


no magic, just build a class-lib project and then ref-the dll in another project.
csc.exe /t:module and al.exe are your friends Big Smile
dotnetjunkie wrote:
I thought that in VS2005 you could have .cs and .vb files in the same project?
you can have files in different languages in the same project, if you are using C++/CLI, at least in Beta 1, 2 you could.
We can mix up both C# and VB.Net in App_Code. For that purpose we have to perform these two steps:
1. Create two subdirectories in App_Code folder one each for C# and VB.Net. Let suppose i have created directory named "VBCode" for VB.Net and "CSCode" for C#.
2. Modify the complition section of web.config file like this

<compilation>
     <codeSubDirectories>
            <add directoryName="VBCode"/>
            <add directoryName="CSCode"/>
      </codeSubDirectories>
</compilation>

odujosh
odujosh
Need Microsoft SUX now!
You can also make a class lib project (compiles to dll) and put the respective code in their own projects in the bin directory of website. I highley recommend this approach. I am not sure I see the benifit of using app_code except in really trivial cases or pages like global.ASAX. I would avoid it. dlls make utility code more distributable. (of course I do not condone dll spam, making yet another dll)

as the explanation above, you can mix C# and VB.Net code together by using the correct configuration. Mr. Dino Esposito's book Programming Microsoft ASP .Net 2.0 Core Reference describes this as well. BUt you have to have both VB.Net and C# compiler installed for this to work.

the code in the app_code does get compiled on-the-fly. Actually, what happens is the code in the app_code get copied to a temporary folder, classes based on the aspx page combined with code behind gets generated and placed also in the temporary folder. Each codes will be compiled by the appropriate compilers and then linked to each other and gets deployed to asp.net. You can see the generated code in the temporary folder. in my pc it is under C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files

punkouter wrote:
BUt you have to have both VB.Net and C# compiler installed for this to work.
with .NET framework how could you not have them both?
there are cases where we may not have C# and VB.Net compiler installed. the fact alone that we are developing on .Net Framework does not mean that we have those compiler installed. .Net Framework IS a framework afterall. It's a set of libraries where we develop on. FOr instance, If you installed visual web developer express, the distribution DOES include VB.Net and C# compiler. but if you only installed visual C# express, then you wont have the VB.Net compiler, yet, you can still develop using .Net Framework isn't it? With ASP.Net, given the proper settings,  I think it is possible to develop on other languages, such as IronPython or IronRuby, maybe C Omega and F#. As long those languages have compiler that targets CLR anything goes. That's what language independence all about.
punkouter wrote:
there are cases where we may not have C# and VB.Net compiler installed. the fact alone that we are developing on .Net Framework does not mean that we have those compiler installed.
again, Microsoft .NET Framework contains a C# compiler (csc.exe) and a VB compiler (vbc.exe) you don't need to install the SDK or any IDE to have the compilers
MikeeeG
MikeeeG
Only the few against the many
"JohnAskew--
Maybe compile one as a dll with a nice Interface(s) and use it in the other project through a reference? "


That would be the most likely thing to do. keeping both apart but talking to each other.
Sven Groot
Sven Groot
My name has 9 letters. Coincidence? I think not...
punkouter wrote:
there are cases where we may not have C# and VB.Net compiler installed.

The base framework comes with both compilers. You don't need anything else, not even the SDK. Everybody who has the .Net Framework has both the VB and the C# compiler.
page 1 of 1
Comments: 23 | Views: 16015
Microsoft Communities