简体   繁体   中英

Is it possible to have C# and vb.net in the same asp.net website?

Is it possible to have C# and vb.net in the same asp.net website? without separating in class libraries.

Try this in the App_Code subfolder create 2 new subfolders, one for your C# classes and another for your VB.NET classes. After that specify these 2 folders in the web.config in the section like this:

<system.web>

<compilation debug="true">

<codeSubDirectories>

<add directoryName="CSharp"/>

<add directoryName="VB"/>

</codeSubDirectories>

</compilation>

Or you can create new project in other language and add referenc to it.

No - the compiler needs code files in different languages to be compiled separately. AC# class library cannot contain VB.NET code, simply because the compiler can't distinguish which code files are written in which language.

If you have a Web Application project, then it's possible.

If you have a Web Site project, then it's not possible.

At a very theoretical level it is possible. As some people here have noted, it is possible to use various techniques to have multiple class libraries in the same application, each written in a different programming language. In the end it simulates the experience of writing a single application in multiple languages. I would say that most of the time that should be sufficient.

There is also a little known feature of .NET and the CLR called a "net module". See this blog post for an explanation on net modules and assemblies (and even multi-file assemblies!).

Having said all this, my first recommendation would be to just choose one language and stick to it. If that isn't an option, having multiple assemblies is a good choice. Using the App_Code trick mentioned by Florim will allow you to keep all your files in one project, even though multiple assemblies will be created on disk by ASP.NET (you'll never see them though).

If you have some worries about having multiple assemblies as opposed to multiple projects then it would be helpful to find out what the concern is. ASP.NET projects, one way or another, almost always get compiled into multiple assemblies. There are tricks to avoid that, but they are seldom used (such as the aspnet_compiler and aspnet_merge).

when tried I found out that you can't (by default) have different languages in a website under App_Code folder.but for other files outside (App_Code) yes you can.

to be able to have different languages under App_Code you need the technique mentioned by Florim.

thank you all guys for help.

用不同的语言进行尝试是不可能的

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM