简体   繁体   English

如何在ASP.Net的App_Code文件夹中引用用另一种语言编写的代码?

[英]How can you reference code written in another language in the App_Code folder in ASP.Net?

Due to legacy issues I have two folders under App_Code directory. 由于遗留问题,我在App_Code目录下有两个文件夹。 One for VB.Net and another for C#. 一个用于VB.Net,另一个用于C#。 Problem is, I have a service in the C# folder that needs to leverage a class in the VB.Net folder but they dont seem to know about each other. 问题是,我在C#文件夹中有一个服务,需要利用VB.Net文件夹中的类,但是他们似乎彼此不了解。 Any ideas are welcome :) 任何想法都欢迎:)

Thanks in advance! 提前致谢!

Trev 崔佛

I had this same problem and ended up having to move the code to a class library and not use App_Code, so my answer is: 我遇到了同样的问题,最终不得不将代码移到类库中而不使用App_Code,所以我的答案是:

Unless someone has a solution for you, move your code that needs to be seen by both into a separate class library project. 除非有人为您提供解决方案,否则将两者都需要查看的代码移到单独的类库项目中。

Here is a very good example about mixing C# and VB in the same Web project... 是一个关于在同一Web项目中混合C#和VB的很好的例子。

The trick is done using the codeSubDirectories compilation element in your application's Web.config, to define code directories that will be compiled into separate assemblies at build or run time... 使用应用程序的Web.config中的codeSubDirectories编译元素可以完成此技巧,以定义将在构建或运行时编译为单独程序集的代码目录。

Here's one approach: http://www.aspnetlibrary.com/articledetails.aspx?article=Use-C-Sharp-and-VB.NET-in-the-same-project . 这是一种方法: http : //www.aspnetlibrary.com/articledetails.aspx ?article= Use-C-Sharp-and-VB.NET-in-the-same-project

See also: Can you mix .net languages within a single project? 另请参阅: 您可以在一个项目中混合使用.net语言吗? .

If you're already set up as described in the article and the problem is calling one App_Code sub-directory from another, you have to refactor a bit. 如果您已经按照本文中的描述进行了设置,而问题是从另一个目录中调用一个App_Code子目录,则必须进行一些重构。 You mention it's a service calling the other sub-directory. 您提到这是调用另一个子目录的服务。 Consider moving the service's code-behind to the same directory as its .asmx. 考虑将服务的代码后移到与其.asmx相同的目录中。 That way, it can use code from anywhere in App_Code. 这样,它可以在App_Code中的任何位置使用代码。 If your service is in the wrong language for the project, you'll have to re-write it. 如果您的服务使用的项目语言错误,则必须重新编写。

Maybe consider translating your VB code into C#? 也许考虑您的VB代码转换为C#? This has the added benefit of making your project more consistent and maintainable. 这具有使您的项目更加一致和可维护的附加好处。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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