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

时间:2021-07-21 08:10:05

Due to legacy issues I have two folders under App_Code directory. One for VB.Net and another for 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. Any ideas are welcome :)

由于遗留问题,我在App_Code目录下有两个文件夹。一个用于VB.Net,另一个用于C#。问题是,我在C#文件夹中有一个服务需要利用VB.Net文件夹中的一个类,但他们似乎并不知道彼此。欢迎任何想法:)

Thanks in advance!

提前致谢!

Trev

4 个解决方案

#1


1  

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.

除非有人为您提供解决方案,否则请将两者需要看到的代码移动到单独的类库项目中。

#2


1  

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编译元素来完成这个技巧,以定义将在构建或运行时编译为单独程序集的代码目录...

#3


0  

Maybe consider translating your VB code into C#? This has the added benefit of making your project more consistent and maintainable.

也许考虑将你的VB代码翻译成C#?这样做的另一个好处是可以使您的项目更加一致和可维护。

#4


0  

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. 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. That way, it can use code from anywhere in App_Code. If your service is in the wrong language for the project, you'll have to re-write it.

如果您已按照本文中的描述进行了设置,并且问题是从另一个调用一个App_Code子目录,则必须重构一下。你提到它是一个调用另一个子目录的服务。考虑将服务的代码隐藏移动到与其.asmx相同的目录。这样,它可以使用App_Code中任何位置的代码。如果您的服务使用的是项目的错误语言,则必须重新编写。

#1


1  

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.

除非有人为您提供解决方案,否则请将两者需要看到的代码移动到单独的类库项目中。

#2


1  

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编译元素来完成这个技巧,以定义将在构建或运行时编译为单独程序集的代码目录...

#3


0  

Maybe consider translating your VB code into C#? This has the added benefit of making your project more consistent and maintainable.

也许考虑将你的VB代码翻译成C#?这样做的另一个好处是可以使您的项目更加一致和可维护。

#4


0  

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. 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. That way, it can use code from anywhere in App_Code. If your service is in the wrong language for the project, you'll have to re-write it.

如果您已按照本文中的描述进行了设置,并且问题是从另一个调用一个App_Code子目录,则必须重构一下。你提到它是一个调用另一个子目录的服务。考虑将服务的代码隐藏移动到与其.asmx相同的目录。这样,它可以使用App_Code中任何位置的代码。如果您的服务使用的是项目的错误语言,则必须重新编写。