多语言网站无法在 C# 代码中使用 VB.NET 类
我正在 VS 2008 中使用 VB.NET 默认语言为网站项目开发一个新功能。由于我的首选语言是 C#,我在 App_Code
文件夹中为 C# 代码创建子文件夹,并添加适当的 web.config 文件中的 codeSubDirectories
元素。问题是我无法在 C# 代码中引用 VB.NET 类。所有 VB.NET 类和结构都放置在 App_Code 中的全局命名空间中。但即使我将一些 VB.NET 类放在与 C# 中的类相同的命名空间中,我仍然无法使用它们。另外,我尝试将我的类移至全局命名空间,但这也对我没有帮助。
I'm developing a new functionality for web site project with VB.NET default language in VS 2008. As my preferred language is C# I create subfolder for C# code in the App_Code
folder and add appropriate codeSubDirectories
element to web.config file. The problem is that I can't refer VB.NET classes in my C# code. All VB.NET classes and structures are placed in global namespace in the App_Code. But even if I place some VB.NET class in the same namespace I've use for my classes in C#, I still can't use them. Also, I've try to move my class to global namespace but this also doesn't help me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
从 codeSubDirectories 的文档中:
这意味着当编译 C# 代码时,VB 代码尚未编译。您可能会尝试分离基类等,并将它们放入较早的子目录或已编译的类库中,但我可能建议只用 VB 编写代码 - 编写起来并不困难。当你习惯了另一种时,框架仍然是框架。
From the documentation for codeSubDirectories:
Which implies that when your C# code is being compiled, the VB code hasn't been compiled at that point. You might try and separate base classes, etc, and put them in an earlier subdirectory or into a compiled class library, but I'd probably recommend just writing your code in VB - it's not that tricky to write in one when you're used to the other - the framework is still the framework.
在App_Code文件夹下创建两个文件夹,分别命名为CSCode和VBCode。将相应的文件移至相关文件夹
在 web.config 文件中添加以下代码:
然后尝试...
-Rakesh
Create two folders under App_Code folder named CSCode and VBCode. Move your respective files to respected folders
Add below code in web.config file:
and then try...
-Rakesh