自动编译.CS类??? [英] Auto-Comilation of .CS classes???

查看:47
本文介绍了自动编译.CS类???的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我喜欢我可以使用嵌入的CS代码或代码隐藏文件创建ASPX和ASCX文件,ASP.NET将为我自动编译它。我*喜欢*那样的方式


有没有办法在.cs文件中定义类,并让我的ASPX,ASCX和Code-Behind文件访问它们而不必先手动编译它们???

I love that I can create ASPX and ASCX files with CS code embedded or in code-behind files and ASP.NET will auto-compile it all for me. I *like* it that way

Is there ANY way to have classes defined in .cs files somewhere and have them accessed by my ASPX, ASCX, and Code-Behind files WITHOUT having to manually compile them first???

推荐答案




根据我的理解,你的问题是什么提到:

"有没有办法在.cs文件中定义类,并且我的ASPX,ASCX和Code-Behind文件没有访问
必须首先手动编译
????


意味着您只想提供某个.cs代码隐藏类的源代码?br />
文件用于aspx页面或ascx控件而不将cs文件编译成

汇编并让它们在运行时编译,当某个页面或ascx

请求控制,是吗?


如果是这样,我认为你可以使用Src @Page或@Control

指令中的属性,例如:

<%@ Page language =" c#" SRC =" xxx.cs" >

<%@ Control Language =" c#" SRC =" xx.cs" >


Src将使代码隐藏类文件按需编译

而不是预编译。并且

Src属性列出了代码隐藏的相对路径

类文件(SrcSample.aspx.cs),并且Inherits属性值是

设置为引用某些class(具有完整命名空间的classname)。在

另外,当你使用Src时,根据需要在运行时编译代码隐藏类

的属性,你必须确保在web应用程序的引用路径中的现有程序集中没有预编译的类。 ,另外,

你会遇到一些意想不到的错误。有关详细信息,请参阅

以下kb文章:


#INFO:ASP.NET代码隐藏模型概述
http://support.microsoft.com/?id=303247


#HOW TO:使用Visual C#.NET在ASP.NET应用程序中使用代码隐藏类文件
http://support.microsoft.com/?id=308143


问候,


Steven Cheng

微软在线支持


安全! www.microsoft.com/security

(此帖子按原样提供,不作任何保证,并且不授予

权利。)


在ASP.NET上获取预览whidbey
< a rel =nofollowhref =http://msdn.microsoft.com/asp.net/whidbey/default.aspxtarget =_ blank> http://msdn.microsoft.com/asp.net/whidbey /default.aspx

Hi,

Based my understanding, does the problem you mentioned as:
"Is there ANY way to have classes defined in .cs files somewhere and have
them accessed by my ASPX, ASCX, and Code-Behind files WITHOUT having to
manually compile them first???"

means that you just want to provide a certain .cs codebehind class''s source
file for a aspx page or ascx control without compiling the cs file into
assembly and let them be compiled at runtime when the certain page or ascx
control is requested, yes?

If so, I think you can use the "Src" attribute in the @Page or @Control
directive, for example:
<%@ Page language="c#" Src="xxx.cs" >
<%@ Control Language="c#" Src="xx.cs" >

The "Src" will make the code-behind class files be compiled on demand
instead of precompiled. And
the "Src" attribute is listed with the relative path of the code-behind
class file (SrcSample.aspx.cs), and that the Inherits attribute value is
set to reference the certain class(classname with full namespace). In
addition, when you use the "Src" attribute to make the code-behind class
compiled at runtime on demand, you must make sure no precompiled classes in
the existing assemblies in the web application''s reference path, othewise,
you''ll encounter some unexpected errors. For detailed info, please refer to
the following kb articles:

#INFO: ASP.NET Code-Behind Model Overview
http://support.microsoft.com/?id=303247

#HOW TO: Work with Code-Behind Class Files in an ASP.NET Application by
Using Visual C# .NET
http://support.microsoft.com/?id=308143

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx





根据我的理解,你提到的问题是什么as:

是否有任何方法可以在.cs文件中定义类,并且我的ASPX,ASCX和Code-Behind文件可以访问
to

首先手动编译它们?


意味着您只想提供某个.cs代码隐藏类的源代码
文件用于aspx页面或ascx控件而不将cs文件编译成

程序集并让它们编译在运行时请求某个页面或ascx

控件,是吗?


如果是这样,我认为你可以使用Src @Page或@Control

指令中的属性,例如:

<%@ Page language =" c#" SRC =" xxx.cs" >

<%@ Control Language =" c#" SRC =" xx.cs" >


Src将使代码隐藏类文件按需编译

而不是预编译。并且

Src属性列出了代码隐藏的相对路径

类文件(SrcSample.aspx.cs),并且Inherits属性值是

设置为引用某些class(具有完整命名空间的classname)。在

另外,当你使用Src时,根据需要在运行时编译代码隐藏类

的属性,你必须确保在web应用程序的引用路径中的现有程序集中没有预编译的类。 ,另外,

你会遇到一些意想不到的错误。有关详细信息,请参阅

以下kb文章:


#INFO:ASP.NET代码隐藏模型概述
http://support.microsoft.com/?id=303247


#HOW TO:使用Visual C#.NET在ASP.NET应用程序中使用代码隐藏类文件
http://support.microsoft.com/?id=308143


问候,


Steven Cheng

微软在线支持


安全! www.microsoft.com/security

(此帖子按原样提供,不作任何保证,并且不授予

权利。)


在ASP.NET上获取预览whidbey
< a rel =nofollowhref =http://msdn.microsoft.com/asp.net/whidbey/default.aspxtarget =_ blank> http://msdn.microsoft.com/asp.net/whidbey /default.aspx

Hi,

Based my understanding, does the problem you mentioned as:
"Is there ANY way to have classes defined in .cs files somewhere and have
them accessed by my ASPX, ASCX, and Code-Behind files WITHOUT having to
manually compile them first???"

means that you just want to provide a certain .cs codebehind class''s source
file for a aspx page or ascx control without compiling the cs file into
assembly and let them be compiled at runtime when the certain page or ascx
control is requested, yes?

If so, I think you can use the "Src" attribute in the @Page or @Control
directive, for example:
<%@ Page language="c#" Src="xxx.cs" >
<%@ Control Language="c#" Src="xx.cs" >

The "Src" will make the code-behind class files be compiled on demand
instead of precompiled. And
the "Src" attribute is listed with the relative path of the code-behind
class file (SrcSample.aspx.cs), and that the Inherits attribute value is
set to reference the certain class(classname with full namespace). In
addition, when you use the "Src" attribute to make the code-behind class
compiled at runtime on demand, you must make sure no precompiled classes in
the existing assemblies in the web application''s reference path, othewise,
you''ll encounter some unexpected errors. For detailed info, please refer to
the following kb articles:

#INFO: ASP.NET Code-Behind Model Overview
http://support.microsoft.com/?id=303247

#HOW TO: Work with Code-Behind Class Files in an ASP.NET Application by
Using Visual C# .NET
http://support.microsoft.com/?id=308143

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx


史蒂文,


不为Alex发言:)但是,我相信他的问题类似于我的问题

(几小时前作为subj:JIT程序集发布)...


基本上,问题是不使用按需编译 (通过指定

SRC),它正在使用_other_按需编译。来自代码背后的类

类。简而言之,我只需使用

@Assembly指令(src =" mytestfile.cs")就可以在.aspx页面中执行此操作...但是,如何从
CodeBehind?有没有办法构建对.cs文件的引用?


要复制下面的示例,请假设以下testclass.cs文件,即

按需编译:


名称空间testnamespace

{

公共类testclass

{

public static string teststring =" teststring" ;;

public testclass()

{

}
}

}


如果我有一个没有代码的页面,我可以使用以下方式访问此课程:

<%@ Assembly Src =" testclass.cs" %>

....

<%

Response.Write(testnamespace.testclass.teststring);

%>


你能告诉我如何从后面的代码中使用这个类(根据需要编译

)?


Brian


" Steven Cheng [MSFT]" <,V - ****** @ online.microsoft.com>在消息中写道

news:bx ************** @ cpmsftngxa06.phx.gbl ...
Steven,

Not to speak for Alex :) but, I believe his problem is similar to mine
(which is posted a few hours ago as subj: JIT assemblies)...

Basically, the problem is not using "compile on demand" (via specifying
SRC), it''s using _other_ "compile on demand" classes from the code behind
class. In short, I can do this in the .aspx page simply by using a
@Assembly directive (src="mytestfile.cs") ... but, how to do this from the
CodeBehind? Is there a way to build a reference to the .cs file?

To copy my example below, assume the following testclass.cs file, that is
compiled on demand:

namespace testnamespace
{
public class testclass
{
public static string teststring = "contents of teststring";
public testclass()
{
}
}
}

If I have a page w/o a code behind, I can access this class using:
<%@ Assembly Src="testclass.cs" %>
....
<%
Response.Write(testnamespace.testclass.teststring) ;
%>

Can you show me how to use this class from a code behind (that is compiled
on demand)?

Brian


"Steven Cheng[MSFT]" <v-******@online.microsoft.com> wrote in message
news:bx**************@cpmsftngxa06.phx.gbl...

根据我的理解,您提到的问题是:
是否有任何方法可以在.cs文件中定义类,并通过我的ASPX,ASCX和它们访问它们Code-Behind文件,无需先手动编译它们?

意味着您只想提供某个.cs代码隐藏类的
源文件对于aspx页面或ascx控件而不将cs文件编译成
程序集并让它们在运行时在请求某个页面或ascx
控件时进行编译,是吗?

如果所以,我认为你可以使用Src @Page或@Control
指令中的属性,例如:
<%@ Page language =" c#" SRC =" xxx.cs" >
<%@ Control Language =" c#" SRC =" xx.cs" >

Src将使代码隐藏类文件按需编译而不是预编译。并且
Src使用代码隐藏类文件(SrcSample.aspx.cs)的相对路径列出属性,并将Inherits属性值设置为引用特定类(具有完整命名空间的类名)。另外,当你使用Src时,在运行时按需编译代码隐藏类的属性,你必须确保在Web应用程序的参考路径中的现有程序集中没有预编译的类
,其他,
你会遇到一些意想不到的错误。有关详细信息,请参阅以下kb文章


#INFO:ASP.NET代码隐藏模型概述
http://support.microsoft.com/?id=303247

#HOW TO:通过使用Visual C#.NET处理ASP.NET应用程序中的代码隐藏类文件
http://support.microsoft.com/?id=308143

问候,

Steven Cheng
Microsoft在线支持

获得安全! www.microsoft.com/security
(此帖已提供按原样,没有任何保证,也没有授予
权利。)

在ASP.NET上预览whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx



这篇关于自动编译.CS类???的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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