混合 C# &同项目中的VB [英] Mixing C# & VB In The Same Project

查看:24
本文介绍了混合 C# &同项目中的VB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你可以在一个类库的同一个项目中混合 vb 和 c# 文件吗?有什么设置可以实现吗?

Can you mix vb and c# files in the same project for a class library? Is there some setting that makes it possible?

我尝试过,但没有一个智能感知可以正常工作,尽管后台编译器似乎可以很好地处理它(除了我在同一个命名空间中有 2 个具有相同名称的类并且它没有抱怨).

I tried and none of the intellisense works quite right, although the background compiler seems to handle it well enough (aside from the fact that I, then, had 2 classes in the same namespace with the same name and it didn't complain).

我们正在尝试从 VB 转换为 C#,但尚未完成所有代码的转换.我有一些需要编写的新代码,但并不真的想为此创建一个新项目.

We're trying to convert from VB to C# but haven't finished converting all the code. I have some new code I need to write, but didn't really want to make a new project just for it.

推荐答案

不,你不能.程序集/项目(每个项目通常编译为 1 个程序集)必须是一种语言.但是,您可以使用多个程序集,每个程序集都可以用不同的语言编码,因为它们都编译为 CIL.

No, you can't. An assembly/project (each project compiles to 1 assembly usually) has to be one language. However, you can use multiple assemblies, and each can be coded in a different language because they are all compiled to CIL.

它编译得很好并且没有抱怨,因为 VB.NET 项目只会实际编译 .vb 文件,而 C# 项目只会实际编译 .cs 文件.它忽略了其他的,因此您没有收到错误.

It compiled fine and didn't complain because a VB.NET project will only actually compile the .vb files and a C# project will only actually compile the .cs files. It was ignoring the other ones, therefore you did not receive errors.

如果将 .vb 文件添加到 C# 项目,请在解决方案资源管理器"面板中选择该文件,然后查看属性"面板,您会注意到构建操作是内容",而不是编译".它被视为一个简单的文本文件,甚至不会作为二进制资源嵌入到已编译的程序集中.

If you add a .vb file to a C# project, select the file in the Solution Explorer panel and then look at the Properties panel, you'll notice that the Build Action is 'Content', not 'Compile'. It is treated as a simple text file and doesn't even get embedded in the compiled assembly as a binary resource.

使用 asp.net 网站,您可以将 c# 网络用户控件添加到 vb.net 网站

With asp.net websites you may add c# web user control to vb.net website

这篇关于混合 C# &同项目中的VB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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