新鲜VS2017网站项目有一个Default.aspx这种方式定义。一个aspx,一个VB和一个C的两个代码隐藏文件#
<%@ Page Title="Home Page" Language="VB" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeFile="Default.aspx.vb" Inherits="_Default" %>
我有一个Default.aspx.vb文件这样规定的:
Partial Public Class _Default : Inherits Page
Public Function Teapot() As Boolean
Return True
End Function
End Class
和Default.aspx.cs文件中像这样:
public partial class _Default : System.Web.UI.Page
{
protected override void OnPreInit(EventArgs e)
{
base.OnPreInit(e); // There is a breakpoint on this line
Teapot(); // Error: The name 'Teapot' does not exist
in the current context
}
}
该网站确实运行,尽管设计时使用Teapot()的错误,并且断点被标记为The breakpoint will not currently be hit.
这就好像C#文件的内容没有被包含在项目中,尽管使用了部分类并且包含在web.config中如下:
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs"
type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.7.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
warningLevel="4" compilerOptions="/langversion:default /nowarn:1659;1699;1701"/>
<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb"
type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.7.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
warningLevel="4" compilerOptions="/langversion:default /nowarn:41008 /define:_MYTYPE=\"Web\" /optionInfer+"/>
</compilers></system.codedom>
我怎样才能获得C#和VB两个文件的内容包含在_Default
页面类?
您不能将C#和VB部分类组合在一起 - 它们使用不同的编译器。 – Dai
我知道,但既然他们都编译到MSIL,我想也许他们可以在这个阶段加入。 – davecove
好吧,使用Ujjwal在接受的答案中指出的文章中描述的App_Code的两个子文件夹,您可以用一种语言编写一个类,该语言可以从用另一种语言编写的_Default类中调用(全部在相同网络项目)。不同于两种语言的部分类,但非常接近。 – davecove