在 ASP.Net 网站项目中混合使用 VB.Net 和 C# 代码? [英] Mixing VB.Net and C# Code in an ASP.Net Web Site project?

查看:17
本文介绍了在 ASP.Net 网站项目中混合使用 VB.Net 和 C# 代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题很老而且经常被问到,我在这里也有类似的问题,但我的问题更具体一些.

The question quite an older and often asked around, i have similar questions here but my question is a bit more specific.

第一季度.在 ASP.Net 网站中混合 C# 和 VB.Net 代码是否合法?它会起作用吗?如果它有效,怎么做?任何样品都会很好.

Q1. Is it legal to mix C# and VB.Net code in ASP.Net Web site? Will it work or not? If it works how it may be done? Any sample will be good.

第 2 季度.如果混合 C# 和 VB.Net 代码有任何影响,那么也请分享这些.

Q2. If there are any repercussions of mixing C# and VB.Net code then please do share those as well.

我有一个用 VB.Net 编码的 Web 项目.我正在研究该项目的一个模块.我想用 C# 编码.我无法将整个项目转换为 C#,因为我不是唯一一个在该项目上工作的人.但是,我打算构建的模块,我想用 C# 构建.

I have a web project that is coded in VB.Net. I am working on one module of the project. and i want to code in C#. I cant convert the whole project to C# because i am not the only one working on the project. However, the module i intend to build , i want to have that built in C#.

我听说在 Web 项目的情况下,如果我们用 C# 编写代码,用 VB.net 编写代码,那么将项目编译为 dll 就会出现问题.真的吗?如果是,那么解决方案是什么.

I have heard that in case of web projects, if we code part in C# and part in VB.net then there are problems compiling the project to a dll. Is that true? if yes then what is the solution.

另外,如果我在 .Net 中构建动态链接库,那么我可以混合使用 C# 和 Vb.Net 代码吗?

Also, if i am building a dynamic link library in .Net then can i mix C# and Vb.Net code?

推荐答案

来自 http://msdn.microsoft.com/en-us/library/t990ks23.aspx:

App_Code 文件夹中的多种编程语言

因为 App_Code 文件夹中的源代码被编译成单个程序集,所以 App_Code 文件夹中的所有文件必须使用相同的编程语言.例如,App_Code 文件夹不能同时包含 Visual Basic 和 C# 中的源代码.

Because the source code in the App_Code folder is compiled into a single assembly, all the files in the App_Code folder must be in the same programming language. For example, the App_Code folder cannot include source code in both Visual Basic and C#.

但是,您可以将 Web 应用程序配置为将 App_Code 文件夹的子文件夹视为单独的可编译单元.然后,每个文件夹都可以包含不同编程语言的源代码.通过在 Web.config 文件的编译元素中创建 codeSubDirectories 元素并添加对子文件夹的引用来指定配置.以下示例说明了如何配置名为 VBCode 和 CSCode 的子文件夹以编译为单独的程序集:

However, you can configure your Web application to treat subfolders of the App_Code folder as separate compilable units. Each folder can then contain source code in a different programming language. The configuration is specified by creating a codeSubDirectories element in the compilation element of the Web.config file and adding a reference to the subfolder. The following example illustrates how you would configure subfolders named VBCode and CSCode to compile into separate assemblies:

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

对 VBCode 和 CSCode 子文件夹的引用不需要包含有关子文件夹中包含的编程语言的任何信息.与 App_Code 文件夹本身一样,ASP.NET 会根据子文件夹中的文件推断要使用的编译器.

The references to the VBCode and CSCode subfolders do not need to include any information about what programming language is contained in the subfolder. As with the App_Code folder itself, ASP.NET infers the compiler to use based on the files in the subfolder.

这篇关于在 ASP.Net 网站项目中混合使用 VB.Net 和 C# 代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆